Find the answer to your Linux question:
Results 1 to 9 of 9
Hi, I'm writing a network driver for a network interface card. The interface with the HW is still rough and not complete. For now - we still don't have interrupts. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2014
    Posts
    6

    Network driver without interrupts


    Hi,

    I'm writing a network driver for a network interface card. The interface with the HW is still rough and not complete.
    For now - we still don't have interrupts. I still want to check the rx path, so instead of interrupts, I want to poll on a part of a mapped area (synced with the driver, which will notify me by writing to it once a frame enters).
    My question is - how do I trigger such a polling? I mean - it's not Napi, since for Napi interrupts must be enabled (for it to disable it, isn't it right?), and I'm not going through any handler since... well, since there're no interrupts... Only un-logical solution I came up with is calling the rx_poll method at the end of the open() method, and stick there until something arrives. But that's really bad, plus - it will only be good for some basic checking, I wouldn't be able to give such a driver to the upper layers apps developers...
    Any ideas?

    Thanks!
    Roy

  2. #2
    Linux Guru
    Join Date
    Dec 2013
    Posts
    1,570
    Funny,someone was asking a similar question just a couple of days ago. There is a kernel patch available that will allow the inotify interface to be used with a memory mapped file. https://gist.github.com/TheCodeArtist/5874669

  3. #3
    Just Joined!
    Join Date
    May 2014
    Posts
    6
    Thanks, that'll help too
    Also - forgot to mention I'm a newbie... timer interrupts was what I was looking for

  4. $spacer_open
    $spacer_close
  5. #4
    Linux User
    Join Date
    Mar 2013
    Posts
    401
    you mean you use a timer interrupt to poll the network interface for data entering?

    (i don't have much idea about linux kernel specifics, btw, but i am interested in low level stuff).

  6. #5
    Just Joined!
    Join Date
    May 2014
    Posts
    6
    Yes, exactly

  7. #6
    Linux User
    Join Date
    Mar 2013
    Posts
    401
    Isn't that risky? What if the kernel doesn't schedule your code fast enough to poll often enough, and you lose characters or numbers that are coming in?

    I'm very curious as to why servers crash under high load - surely whatever your code does to take data from the network interface and put it into RAM, checks whether enough RAM is available first....? If so, then why does a server crash?

  8. #7
    Linux Guru
    Join Date
    Dec 2013
    Posts
    1,570
    All resources in the computer are finite. Memory is just one of them but ...

    Linux practises what is known as optimistic memory allocation (some way it's a feature, some say it's a bug). That is to say it always returns memory to the requestor, even when none exists, presuming that when it is actually used it will be available. Per process memory limits can be set but I'm talking about system memory.

    So:

    Code:
    unsigned char* buf = malloc (MY_HUGH_BUFFER_VAL);
    
    if (buf == NULL) {
        perror ("Malloc failed");
        exit (EXIT_FAILURE);
    }
    which is the standard form in C for doing this, is essentially meaningless. Which isn't to say you shouldn't do it anyway.

    There is no way in Linux to be sure whether the memory is there unless you implement your own memory manager, which is to say grab the memory and initialize it when your process starts. It won't preclude a crash though since that could occur elsewhere in the chain and for another reason (i.e. no more file descriptors).

  9. #8
    Linux User
    Join Date
    Mar 2013
    Posts
    401
    Well, that's a pretty ****** OS then, isn't it......?!!!!

    Also, I'm not really a C guy, what does NULL mean exactly? (I take it it's not a boolean NULL, the same way it is in Javascript....? )

  10. #9
    Linux Guru
    Join Date
    Dec 2013
    Posts
    1,570
    Well, to some people it's a feature and to some it's a bug. The problem with being out of memory is there's very little an application can do to handle it - so Linux makes a best effort to handle it at an OS level. An application could potentially free up some of it's own memory and hope for the best but in reality, if a multiprocess system is out of memory you're hooped anyway.

    A pointer is a location in memory. NULL is a way to initialize it to a value that can't be used in a valid program. It's an implementation defined macro that most often looks like:
    Code:
    #if !defined(NULL)
        #define NULL ((void*)0)
    #endif

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •