函数逻辑报告

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:kernel\events\core.c Create Date:2022-07-27 15:00:49
Last Modify:2022-05-20 07:50:19 Copyright©Brick
首页 函数Tree
注解内核,赢得工具下载SCCTEnglish

函数名称:Allocate and initialize an event structure

函数原型:static struct perf_event *perf_event_alloc(struct perf_event_attr *attr, int cpu, struct task_struct *task, struct perf_event *group_leader, struct perf_event *parent_event, perf_overflow_handler_t overflow_handler, void *context, int cgroup_fd)

返回类型:struct perf_event

参数:

类型参数名称
struct perf_event_attr *attr
intcpu
struct task_struct *task
struct perf_event *group_leader
struct perf_event *parent_event
perf_overflow_handler_toverflow_handler
void *context
intcgroup_fd
10683  err等于负EINVAL
10685  如果cpu大于等于CPU数量
10686  如果非taskcpu不等于负1则返回:错误号
10690  event等于分配内存并置零
10691  如果非event则返回:错误号
10698  如果非group_leadergroup_leader等于event
10701  mutex_init - initialize the mutex*@mutex: the mutex to be initialized* Initialize the mutex to unlocked state.* It is not allowed to initialize an already locked mutex.( & child_mutex)
10702  初始化链表头
10704  初始化链表头
10705  初始化链表头
10706  初始化链表头
10707  Helper function to initialize event group nodes.
10708  初始化链表头
10709  初始化链表头
10710  初始化链表头
10711  INIT_HLIST_NODE( & hlist_entry)
10714  init_waitqueue_head( & waitq)
10715  pending_disable等于负1
10716  init_irq_work( & pending, perf_pending_event)
10718  mutex_init - initialize the mutex*@mutex: the mutex to be initialized* Initialize the mutex to unlocked state.* It is not allowed to initialize an already locked mutex.( & mmap_mutex)
10719  raw_spin_lock_init( & lock)
10721  atomic_long_set( & refcount, 1)
10722  cpu等于cpu
10723  attr等于attr
10724  group_leader等于group_leader
10725  pmu = NULL
10726  oncpu等于负1
10728  parent等于parent_event
10730  ns等于get_pid_ns(取进程的空间)
10731  id等于atomic64_inc_return( & perf_event_id)
10733  state等于PERF_EVENT_STATE_INACTIVE
10735  如果task
10736  attach_state等于PERF_ATTACH_TASK
10742  target等于get_task_struct(task)
10745  clock等于local_clock
10746  如果parent_eventclock等于clock
10749  如果非overflow_handlerparent_event
10750  overflow_handler等于overflow_handler
10751  context等于overflow_handler_context
10764  如果overflow_handler
10765  overflow_handler等于overflow_handler
10766  overflow_handler_context等于context
10767  否则如果is_write_backward(event)则
10768  overflow_handler等于perf_event_output_backward
10769  overflow_handler_context = NULL
10770  否则
10771  overflow_handler等于perf_event_output_forward
10772  overflow_handler_context = NULL
10775  Initialize event state based on the perf_event_attr::disabled.
10777  pmu = NULL
10779  hwc等于hw
10780  sample_period等于sample_period
10781  如果use freq, not period sample_freqsample_period等于1
10783  last_period等于sample_period
10785  local64_set( & period_left, sample_period)
10791  如果children inherit it sample_type按位与PERF_SAMPLE_READ则转到:err_ns
10794  如果非has_branch_stack(event)则branch_sample_type等于0
10797  如果cgroup_fd不等于负1则
10798  err等于perf_cgroup_connect(cgroup_fd, event, attr, group_leader)
10799  如果err则转到:err_ns
10803  pmu等于perf_init_event(event)
10804  如果是错误
10805  err等于错误
10806  转到:err_ns
10813  如果task_ctx_nr恒等于perf_invalid_contextcgroup_fd不等于负1则
10814  err等于负EINVAL
10815  转到:err_pmu
10818  如果aux_output且非various common per-pmu feature flags按位与PERF_PMU_CAP_AUX_OUTPUT的值则
10820  err等于负EOPNOTSUPP
10821  转到:err_pmu
10824  err等于The following implement mutual exclusion of events on "exclusive" pmus* (PERF_PMU_CAP_EXCLUSIVE)
10825  如果err则转到:err_pmu
10828  如果has_addr_filter(event)则
10829  addr_filter_ranges等于分配数组内存并置零
10832  如果非addr_filter_ranges
10833  err等于负ENOMEM
10834  转到:err_per_task
10841  如果parent
10852  addr_filters_gen等于1
10855  如果非parent
10856  如果sample_type按位与PERF_SAMPLE_CALLCHAIN
10858  如果err则转到:err_addr_filters
10863  err等于security_perf_event_alloc(event)
10864  如果err则转到:err_callchain_buffer
10868  account_event(event)
10870  返回:event
10872  err_callchain_buffer :
10873  如果非parent
10874  如果sample_type按位与PERF_SAMPLE_CALLCHAINput_callchain_buffers()
10877  err_addr_filters :
10878  kfree(addr_filter_ranges)
10880  err_per_task :
10881  exclusive_event_destroy(event)
10883  err_pmu :
10884  如果destroydestroy(event)
10886  module_put(module)
10887  err_ns :
10888  如果is_cgroup_event(event)则perf_detach_cgroup(event)
10890  如果nsput_pid_ns(ns)
10892  如果targetput_task_struct(target)
10894  kfree(event)
10896  返回:错误号
调用者
名称描述
perf_event_create_kernel_counterperf_event_create_kernel_counter*@attr: attributes of the counter to create*@cpu: cpu in which the counter is bound*@task: task to profile (NULL for percpu)
inherit_eventInherit an event from parent task to child task.* Returns:* - valid pointer on success* - NULL for orphaned events* - IS_ERR() on error