linux kernel struct 之 percpu_ida

linux-4.9.37/include/linux/percpu_ida.h

用于管理percpu ID分配器的数据结构,主要用于在多处理器系统中为每个CPU分配唯一的标识符。

percpu ID分配器(percpu_ida)用于为每个CPU分配一个唯一的标识符。这通常用于创建内核线程时为线程命名。例如,在创建工作线程时,每个线程需要一个唯一的ID来区分不同的工作线程。‌

struct percpu_ida {
    /*
     * number of tags available to be allocated, as passed to
     * percpu_ida_init()
     */
    unsigned            nr_tags;
    unsigned            percpu_max_size;
    unsigned            percpu_batch_size;

    struct percpu_ida_cpu __percpu    *tag_cpu;

    /*
     * Bitmap of cpus that (may) have tags on their percpu freelists:
     * steal_tags() uses this to decide when to steal tags, and which cpus
     * to try stealing from.
     *
     * It's ok for a freelist to be empty when its bit is set - steal_tags()
     * will just keep looking - but the bitmap _must_ be set whenever a
     * percpu freelist does have tags.
     */
    cpumask_t            cpus_have_tags;

    struct {
        spinlock_t        lock;
        /*
         * When we go to steal tags from another cpu (see steal_tags()),
         * we want to pick a cpu at random. Cycling through them every
         * time we steal is a bit easier and more or less equivalent:
         */
        unsigned        cpu_last_stolen;

        /* For sleeping on allocation failure */
        wait_queue_head_t    wait;

        /*
         * Global freelist - it's a stack where nr_free points to the
         * top
         */
        unsigned        nr_free;
        unsigned        *freelist;
    } ____cacheline_aligned_in_smp;
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值