Suggestions about protecting data with spinlocks [NEED AN OPINION] - Linux

This is a discussion on Suggestions about protecting data with spinlocks [NEED AN OPINION] - Linux ; Hi, I need to have some opinions about where should I put some spinlocks to protect data inside a kernel module that I'm developing. I'll try to summarize the data structures that I need to use and how they are ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Suggestions about protecting data with spinlocks [NEED AN OPINION]

  1. Suggestions about protecting data with spinlocks [NEED AN OPINION]

    Hi,
    I need to have some opinions about where should I put some spinlocks to
    protect data inside a kernel module that I'm developing. I'll try to
    summarize the data structures that I need to use and how they are
    manipulated.

    The following data structure contains an HW address of a station in a
    wireless network and 4 queues of packets enqueued at the Access Point
    for that station.

    struct _station_data {
    struct list_head list;

    u8 addr[ETH_ALEN];

    struct sk_buff_head queue_ac[AC_QUEUES];

    u32 queue_size_ac[AC_QUEUES];
    };

    Then, I have another data structure, which contains data related to the
    Access Point and a linked list of _station_data data structures:

    struct _host_hcf_ap_data {
    struct proc_dir_entry *proc_dir_host_hcf;

    struct _station_data stations_data; // Linked List
    spinlock_t stations_data_lock;
    };


    These are the actions that manipulate these data structures:

    - Association of a new STA: a new _station_data data structure is added
    to the list
    - Disassiociation of a STA: a _station_data data structure is removed
    from the list
    - Arrival of a SKB (socket buffer, i.e. packet, for a station:
    stations_data list is traversed until the proper _station_data data
    structure is found, then the SKB is enqueued in the proper queue_ac
    SKB-queue.
    - A SKB must be sent out: a _station_data data structure is chosen to
    send a SKB, a SKB is dequeued from one of the queue_ac SKB-queues and
    then it is sent out

    At the moment each of the above operations is implemented in such a way
    that the first thing that it is done is acquiring the
    stations_data_lock spinlock, which protects the Access Point data
    structure and all the list of _station_data data structures.

    Would you protect the data in a different way, in order to be able to
    add a new _station_data data structure and in the same time enqueue a
    skb (which is not possible at the moment because both operations must
    acquire the "global" lock)? I know that I should forget this
    optimization (more than one operation in parallel on the data) since
    I'm working on a single-processor machine (and all these operations are
    done in tasklets, so on a single-CPU machine there is no possibility to
    have more than one of these operations being executed in parallel), but
    I'd like to have your opinion about that..

    I hope I've been quite clear in my explaination.

    Thank you in advance for any suggestion you will give me!
    Gianni


  2. Re: Suggestions about protecting data with spinlocks [NEED AN OPINION]

    On Mon, 24 Jul 2006 10:30:40 -0700, Slaytanic wrote:

    >
    > I hope I've been quite clear in my explaination.
    >

    Is the data for read/write or read-only purpose?
    If read-only you could use a semaphore or monitor. The kernel provides a
    kernel space semaphore. http://lwn.net/Articles/163269/
    Also study Reader/Writer Locks or Big-Reader Locks.
    http://james.bond.edu.au/courses/inf...echniques.html

    --
    Hilsen/Regards
    Michael Rasmussen
    http://keyserver.veridis.com:11371/p...rch=0xE3E80917


  3. Re: Suggestions about protecting data with spinlocks [NEED AN OPINION]


    Michael Rasmussen ha scritto:

    > Is the data for read/write or read-only purpose?
    > If read-only you could use a semaphore or monitor. The kernel provides a
    > kernel space semaphore. http://lwn.net/Articles/163269/
    > Also study Reader/Writer Locks or Big-Reader Locks.


    The data is accessed for both read and write purposes.
    I cannot use semaphores since they can go to sleep and this is not
    allowed in tasklets which run in (software) interrupt context. I gave a
    look also to read-write spinlocks but this kind of spinlock privileges
    readers (i.e. if a reader R1 is helding a read-lock and a writer W1
    tries to acquire the same lock for writing, if another reader R2 comes
    and tries to get the read-lock it can acquire it.. so there is the
    possibility of writer-starvation, which is not something good in my
    case)..

    > http://james.bond.edu.au/courses/inf...echniques.html
    >
    > --
    > Hilsen/Regards
    > Michael Rasmussen
    > http://keyserver.veridis.com:11371/p...rch=0xE3E80917



+ Reply to Thread