kernel/taskstats.c
Source file repositories/reference/linux-study-clean/kernel/taskstats.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/taskstats.c- Extension
.c- Size
- 16174 bytes
- Lines
- 723
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/taskstats_kern.hlinux/tsacct_kern.hlinux/acct.hlinux/delayacct.hlinux/cpumask.hlinux/percpu.hlinux/slab.hlinux/cgroupstats.hlinux/cgroup.hlinux/fs.hlinux/file.hlinux/pid_namespace.hnet/genetlink.hlinux/atomic.hlinux/sched/cputime.h
Detected Declarations
struct listenerstruct listener_listenum actionsfunction prepare_replyfunction send_replyfunction send_cpu_listenersfunction exe_add_tskfunction fill_statsfunction fill_stats_for_pidfunction tgid_stats_add_taskfunction fill_stats_for_tgidfunction fill_tgid_exitfunction add_del_listenerfunction list_for_each_entryfunction list_for_each_entry_safefunction parsefunction cgroupstats_user_cmdfunction cmd_attr_register_cpumaskfunction cmd_attr_deregister_cpumaskfunction taskstats_packet_sizefunction cmd_attr_pidfunction cmd_attr_tgidfunction taskstats_user_cmdfunction taskstats_exitfunction taskstats_init_earlyfunction taskstats_init
Annotated Snippet
struct listener {
struct list_head list;
pid_t pid;
char valid;
};
struct listener_list {
struct rw_semaphore sem;
struct list_head list;
};
static DEFINE_PER_CPU(struct listener_list, listener_array);
enum actions {
REGISTER,
DEREGISTER,
CPU_DONT_CARE
};
static int prepare_reply(struct genl_info *info, u8 cmd, struct sk_buff **skbp,
size_t size)
{
struct sk_buff *skb;
void *reply;
/*
* If new attributes are added, please revisit this allocation
*/
skb = genlmsg_new(size, GFP_KERNEL);
if (!skb)
return -ENOMEM;
if (!info) {
int seq = this_cpu_inc_return(taskstats_seqnum) - 1;
reply = genlmsg_put(skb, 0, seq, &family, 0, cmd);
} else
reply = genlmsg_put_reply(skb, info, &family, 0, cmd);
if (reply == NULL) {
nlmsg_free(skb);
return -EINVAL;
}
*skbp = skb;
return 0;
}
/*
* Send taskstats data in @skb to listener with nl_pid @pid
*/
static int send_reply(struct sk_buff *skb, struct genl_info *info)
{
struct genlmsghdr *genlhdr = nlmsg_data(nlmsg_hdr(skb));
void *reply = genlmsg_data(genlhdr);
genlmsg_end(skb, reply);
return genlmsg_reply(skb, info);
}
/*
* Send taskstats data in @skb to listeners registered for @cpu's exit data
*/
static void send_cpu_listeners(struct sk_buff *skb,
struct listener_list *listeners)
{
struct genlmsghdr *genlhdr = nlmsg_data(nlmsg_hdr(skb));
struct listener *s, *tmp;
struct sk_buff *skb_next, *skb_cur = skb;
void *reply = genlmsg_data(genlhdr);
int delcount = 0;
genlmsg_end(skb, reply);
down_read(&listeners->sem);
list_for_each_entry(s, &listeners->list, list) {
int rc;
skb_next = NULL;
if (!list_is_last(&s->list, &listeners->list)) {
skb_next = skb_clone(skb_cur, GFP_KERNEL);
if (!skb_next)
break;
}
rc = genlmsg_unicast(&init_net, skb_cur, s->pid);
if (rc == -ECONNREFUSED) {
s->valid = 0;
delcount++;
}
skb_cur = skb_next;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/taskstats_kern.h`, `linux/tsacct_kern.h`, `linux/acct.h`, `linux/delayacct.h`, `linux/cpumask.h`, `linux/percpu.h`, `linux/slab.h`.
- Detected declarations: `struct listener`, `struct listener_list`, `enum actions`, `function prepare_reply`, `function send_reply`, `function send_cpu_listeners`, `function exe_add_tsk`, `function fill_stats`, `function fill_stats_for_pid`, `function tgid_stats_add_task`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.