Passing socket struct between kernel threads - module programming


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Passing socket struct between kernel threads - module programming
# 1  
Old 02-12-2009
Error Passing socket struct between kernel threads - module programming

I write kernel module with kernel threads using
linux/kthread.h on 2.6.* kernel

I tried to passing data between two kernel threads
with data argument of kthread_run( fun, data , NAME );
but this is not work I dont know why. I tried many possibility
and nothing works.

So I thought that maybe something like this will work
but not.
Code:
typedef struct my {
    struct socket *tmp;
    struct task_struct *task;
    int (*fun)(void * );
} table[10];
/* this is global static table */

int kthread_fun1(void *d) {
    sock_create( ...., &(tab[0].tmp) )
    printk(" %p ", tab[0].tmp ) <- THIS IS NOT NULL OK
}

int ktrhead_fun2( void *d ) {
    tab[0].tmp <- THIS IS NULL IN THIS CASE WHY

}

init_function_of_module {
    kthread_run( ..., fun1, ... )
 
    kthread_run( ..., fun2, ... )
}

Iam sure that fun1 thread was executed before fun2, I used semaphores ( actually completion mechanism ).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Unload kernel module at boot time (Debian Wheezy 7.2, 3.2.0-4-686-pae kernel)

Hi everyone, I am trying to prevent the ehci_hcd kernel module to load at boot time. Here's what I've tried so far: 1) Add the following line to /etc/modprobe.d/blacklist.conf (as suggested here): 2) Blacklisted the module by adding the following string to 3) Tried to blacklist the module... (0 Replies)
Discussion started by: gacanepa
0 Replies

2. UNIX for Advanced & Expert Users

Get pointer for existing device class (struct class) in Linux kernel module

Hi all! I am trying to register a device in an existing device class, but I am having trouble getting the pointer to an existing class. I can create a class in a module, get the pointer to it and then use it to register the device with: *cl = class_create(THIS_MODULE, className);... (0 Replies)
Discussion started by: hdaniel@ualg.pt
0 Replies

3. IP Networking

help implementing an ip filter in linux/net/socket.c (kernel programming)

hi there so, i was given an assignment: implement a linux system call that blocks all packets that are sent to a given IP (i have to do it without using iptables) i'm really new to kernel programming btw (and i'm enjoying it a lot) so, my syscall is called ip_block() and receives a... (1 Reply)
Discussion started by: lgfaria
1 Replies

4. IP Networking

socket programming using threads

Hi, 1)i wrote a program which acts lik a client gateway serving clients request and sending probe msg`s to server to chech if its active.. 2)both moduels interact when run independently my problem is that when i tr to run them as two different threads in a single program(client_gateway prog to... (4 Replies)
Discussion started by: sameer kulkarni
4 Replies

5. Homework & Coursework Questions

Passing pointers to struct

Hi, i'm trying to copy a struct into a binary file using the unix instruction write, so i declare and fill the struct "superbloque" in one function "initSB" and then i pass the pointer to another function called bwrite (for block write) which calls write. The problem is that i call the function... (2 Replies)
Discussion started by: ignatius3
2 Replies

6. UNIX for Dummies Questions & Answers

Passing struct through unix pipe -solved

EDIT: Nevermind, called a friend who is good at this stuff and he figured it out :D Hi all, So I'm trying to teach myself to write programs for unix in c. I am currently creating a program, and I need to pass a struct through a pipe, but I can't figure out how. The struct I want to pass... (0 Replies)
Discussion started by: twnsfn34
0 Replies

7. Linux

where is struct tq_struct in 2.6 kernel

hi masters, I am new to kernel programming and learning its trade. I am writing a module for lan bandwidth manager. I designed one module successfully for 2.4 kernel . But when I tried to upgrade it for 2.6 kernel I found that struct tq_struct is missing . Is there any suitable replacement for... (0 Replies)
Discussion started by: iamjayanth
0 Replies

8. Linux

How to convert Linux Kernel built-in module into a loadable module

Hi all, I am working on USB data monitoring on Fedora Core 9. Kernel 2.6.25 has a built-in module (the one that isn't loadable, but compiles and links statically with the kernel during compilation) to snoop USB data. It is in <kernel_source_code>/drivers/usb/mon/. I need to know if I can... (0 Replies)
Discussion started by: anitemp
0 Replies

9. SuSE

max number of slabs per kernel module (kernel 2.6.17, suse)

Hi All, Is there a max number of slabs that can be used per kernel module? I'm having a tough time finding out that kind of information, but the array 'node_zonelists' (mmzone.h) has a size of 5. I just want to avoid buffer overruns and other bad stuff. Cheers, Brendan (4 Replies)
Discussion started by: Brendan Kennedy
4 Replies

10. Linux

Making Socket System Call From Linux Kernel Module?

Hi Everyone! How can we make a socket() system call from a linux module executing in kernel space? If any one knows, kindly tell me. It will be great. I want to use the socket interface in linux kernel space for sending raw packets over the network. Hamayun (0 Replies)
Discussion started by: mian_m_hamayun
0 Replies
Login or Register to Ask a Question
KTHREAD(9)						   BSD Kernel Developer's Manual						KTHREAD(9)

NAME
kthread_create, kthread_destroy, kthread_exit, kthread_join -- kernel threads SYNOPSIS
#include <sys/kthread.h> int kthread_create(pri_t pri, int flags, struct cpu_info *ci, void (*func)(void *), void *arg, lwp_t **newlp, const char *fmt, ...); void kthread_destroy(lwp_t *l); void kthread_exit(int ecode); int kthread_join(lwp_t *l); DESCRIPTION
Kernel threads are light-weight processes which execute entirely within the kernel. Any process can request the creation of a new kernel thread. Kernel threads are not swapped out during memory congestion. The VM space and limits are shared with proc0 (usually swapper). FUNCTIONS
kthread_create(pri, flags, ci, func, arg, newlp, fmt, ...) Create a kernel thread. The arguments are as follows. pri Priority level for the thread. If no priority level is desired specify PRI_NONE, causing kthread_create() to select the default priority level. flags Flags that can be logically ORed together to alter the thread's behaviour. ci If non-NULL, the thread will be created bound to the CPU specified by ci, meaning that it will only ever execute on that CPU. By default, the threads are free to execute on any CPU in the system. func A function to be called when the thread begins executing. This function must not return. If the thread runs to comple- tion, it must call kthread_exit() to properly terminate itself. arg An argument to be passed to func(). May be NULL if not required. newlp A pointer to receive the new LWP structure for the kernel thread. May be NULL, unless KTHREAD_MUSTJOIN is specified in flags. fmt A string containing format information used to display the kernel thread name. Must not be NULL. The following flags are defined. KTHREAD_IDLE Causes the thread to be created in the LSIDL (idle) state. By default, the threads are created in the LSRUN (runnable) state, meaning they will begin execution shortly after creation. KTHREAD_MPSAFE Specifies that the thread does its own locking and so is multiprocessor safe. If not specified, the global kernel lock will be held whenever the thread is running (unless explicitly dropped by the thread). KTHREAD_INTR Specifies that the thread services device interrupts. This flag is intended for kernel internal use and should not normally be specified. KTHREAD_TS Causes the kthread to be created in the SCHED_OTHER class (timeshared). The thread's priority will be dynamically adjusted by the scheduler. Increased activity by the kthread will cause its priority to fall; decreased activity will cause its priority to rise. By default, kthreads are created in the SCHED_RR class, with a fixed priority specified by pri. Threads in the SCHED_RR class do not have their priority dynamically adjusted by the scheduler. KTHREAD_MUSTJOIN Indicates that created kthread must be joined. In such case kthread_exit() will wait until kthread_join() will be called. kthread_destroy(l) From another thread executing in the kernel, cause a kthread to exit. The kthread must be in the LSIDL (idle) state. kthread_exit(ecode) Exit from a kernel thread. Must only be called by a kernel thread. kthread_join(l) Suspend execution of calling thread until the target kthread terminates. Conceptually the function can be compared to the user space pthread_join(3), however it must be called only once for kernel thread which was created using the KTHREAD_MUSTJOIN flag and would wait on kthread_exit. RETURN VALUES
Upon successful completion, kthread_create() returns 0. Otherwise, the following error values are returned: [EAGAIN] The limit on the total number of system processes would be exceeded. [EAGAIN] The limit RLIMIT_NPROC on the total number of processes under execution by this user id would be exceeded. CODE REFERENCES
The kthread framework itself is implemented within the file sys/kern/kern_kthread.c. Data structures and function prototypes for the frame- work are located in sys/sys/kthread.h. SEE ALSO
condvar(9), driver(9), softint(9), workqueue(9) HISTORY
The kthread framework appeared in NetBSD 1.4. BSD
August 7, 2011 BSD