Linked lists for userspace programs in Linux
Hi all, I wanted to use linked lists in one of my userspace programs in Linux. I tried two methods, 1. I used the modified version of list implementation given in http://isis.poly.edu/kulesh/stuff/src/klist/list.h for my userspace program. But when I compiled the kernel, there were errors showing 'redefinition of struct', 'conflicting types' etc. 2. When I tried to use list.h as such without any modifications, linked list functions in my userspace program were not identified by the compiler and displayed as undefined. Would it be okay to modify the variable/function names in a copy of list.h and use it in the userspace program ? Please advise. Thank you. Regards, chandru
On Sat, 14 Jun 2014 02:38:19 +0800, Chandrasekaran Sivakumar said:
I wanted to use linked lists in one of my userspace programs in Linux.
Userspace. Remember that word.
1. I used the modified version of list implementation given in http://isis.poly.edu/kulesh/stuff/src/klist/list.h for my userspace program. But when I compiled the kernel, there were errors showing 'redefinition of struct', 'conflicting types' etc.
You're recompiling the kernel for what reason? You seem to be confused regarding kernel space versus userspace programming...
2. When I tried to use list.h as such without any modifications, linked list functions in my userspace program were not identified by the compiler and displayed as undefined.
This sounds like you need an introductory C class. Did you remember to #include them? Oh, by the way, keep in mind that the Linux kernel "linked list" is actually a circularly linked list - as a result, treating it as a normal linked list (particularly when checking for empty list or end-of-list) is likely to result in hilarity and hijinks for all...
Would it be okay to modify the variable/function names in a copy of list.h and use it in the userspace program ?
You'd probably be better off learning basic data structures well enough to write your own implementation.
On Sun, 15 Jun 2014, Valdis.Kletnieks@vt.edu wrote:
Oh, by the way, keep in mind that the Linux kernel "linked list" is actually a circularly linked list - as a result, treating it as a normal linked list (particularly when checking for empty list or end-of-list) is likely to result in hilarity and hijinks for all...
once upon a time, i wrote a piece on how kernel linked lists work, i think it's still accurate. http://crashcourse.ca/introduction-linux-kernel-programming/intermission-let... rday -- ======================================================================== Robert P. J. Day Ottawa, Ontario, CANADA http://crashcourse.ca Twitter: http://twitter.com/rpjday LinkedIn: http://ca.linkedin.com/in/rpjday ========================================================================
Hi, Apologies from me. I didn't explain my problem properly. I am working on modifying the linux kernel's scheduler framework to include support for real-time algorithms. In order to give user inputs such as number of tasks, their execution cost, period, deadline etc, I am creating an userspace program. Then this program would transfer control to the kernel to perform system calls for creation and execution of tasks. Thats why I had to recompile the kernel. I had planned to use linked list to contain the multiple execution cost values in each task (for a mixed criticality task system). As the control is transferred to the kernel, the linked list should be accessed from the kernel side also. As you had suggested, I had written my own implementation of linked lists. Please advise me on how to make this implementation (contained in a header file) common to both kernel and userspace ? Thank you for your time. Regards, chandru On Mon, Jun 16, 2014 at 11:24 AM, <Valdis.Kletnieks@vt.edu> wrote:
On Sat, 14 Jun 2014 02:38:19 +0800, Chandrasekaran Sivakumar said:
I wanted to use linked lists in one of my userspace programs in Linux.
Userspace. Remember that word.
1. I used the modified version of list implementation given in http://isis.poly.edu/kulesh/stuff/src/klist/list.h for my userspace program. But when I compiled the kernel, there were errors showing 'redefinition of struct', 'conflicting types' etc.
You're recompiling the kernel for what reason? You seem to be confused regarding kernel space versus userspace programming...
2. When I tried to use list.h as such without any modifications, linked list functions in my userspace program were not identified by the compiler and displayed as undefined.
This sounds like you need an introductory C class. Did you remember to #include them?
Oh, by the way, keep in mind that the Linux kernel "linked list" is actually a circularly linked list - as a result, treating it as a normal linked list (particularly when checking for empty list or end-of-list) is likely to result in hilarity and hijinks for all...
Would it be okay to modify the variable/function names in a copy of list.h and use it in the userspace program ?
You'd probably be better off learning basic data structures well enough to write your own implementation.
On Mon, 16 Jun 2014 21:35:20 +0800, Chandrasekaran Sivakumar said:
Apologies from me. I didn't explain my problem properly. I am working on modifying the linux kernel's scheduler framework to include support for real-time algorithms. In order to give user inputs such as number of tasks, their execution cost, period, deadline etc, I am creating an userspace program. Then this program would transfer control to the kernel to perform system calls for creation and execution of tasks.
Nope. Wrong answer. You can't do real-time that way. If the userspace code gets hung in a loop or something, your in-kernel scheduler can get stuck with old/stale information, and as a result incorrectly schedule the next process, causing a realtime window to be totally blown. And if all the userspace code is doing is writing config information for which tasks get what priorities, you should be instead extending the sched_setscheduler() syscall, or possibly adding a /proc/PID/<something> interface.
participants (3)
-
Chandrasekaran Sivakumar -
Robert P. J. Day -
Valdis.Kletnieks@vt.edu