Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:kernel\events\core.c Create Date:2022-07-28 13:40:44
Last Modify:2022-05-20 07:50:19 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:Allocate and initialize an event structure

Proto: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)

Type:struct perf_event

Parameter:

TypeParameterName
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  If cpu >= Setup number of possible processor ids Then
10686  If Not task || cpu != -1 Then Return ERR_PTR( - EINVAL)
10690  event = kzalloc - allocate memory. The memory is set to zero.*@size: how many bytes of memory are required.*@flags: the type of memory to allocate (see kmalloc).
10691  If Not event Then Return ERR_PTR( - ENOMEM)
10698  If Not group_leader Then group_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  Initialization list head
10704  Initialization list head
10705  Initialization list head
10706  Initialization list head
10707  Helper function to initialize event group nodes.
10708  Initialization list head
10709  Initialization list head
10710  Initialization list head
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(task_active_pid_ns(current process))
10731  id = atomic64_inc_return( & perf_event_id)
10733  state = PERF_EVENT_STATE_INACTIVE
10735  If task Then
10736  attach_state = PERF_ATTACH_TASK
10742  target = get_task_struct(task)
10745  clock = local_clock
10746  If parent_event Then clock = clock
10749  If Not overflow_handler && parent_event Then
10750  overflow_handler = overflow_handler
10751  context = overflow_handler_context
10764  If overflow_handler Then
10765  overflow_handler = overflow_handler
10766  overflow_handler_context = context
10767  Else if is_write_backward(event) Then
10768  overflow_handler = perf_event_output_backward
10769  overflow_handler_context = NULL
10770  Else
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  If use freq, not period && sample_freq Then sample_period = 1
10783  last_period = sample_period
10785  local64_set( & period_left, sample_period)
10791  If children inherit it && sample_type & PERF_SAMPLE_READ Then Go to err_ns
10794  If Not has_branch_stack(event) Then branch_sample_type = 0
10797  If cgroup_fd != -1 Then
10798  err = perf_cgroup_connect(cgroup_fd, event, attr, group_leader)
10799  If err Then Go to err_ns
10803  pmu = perf_init_event(event)
10804  If IS_ERR(pmu) Then
10805  err = PTR_ERR(pmu)
10806  Go to err_ns
10813  If task_ctx_nr == perf_invalid_context && cgroup_fd != -1 Then
10814  err = -EINVAL
10815  Go to err_pmu
10818  If aux_output && Not (various common per-pmu feature flags & PERF_PMU_CAP_AUX_OUTPUT) Then
10820  err = -EOPNOTSUPP
10821  Go to err_pmu
10824  err = The following implement mutual exclusion of events on "exclusive" pmus* (PERF_PMU_CAP_EXCLUSIVE)
10825  If err Then Go to err_pmu
10828  If has_addr_filter(event) Then
10829  addr_filter_ranges = kcalloc - allocate memory for an array. The memory is set to zero.*@n: number of elements.*@size: element size.*@flags: the type of memory to allocate (see kmalloc).
10832  If Not addr_filter_ranges Then
10833  err = -ENOMEM
10834  Go to err_per_task
10841  If parent Then
10844  raw_spin_lock_irq( & lock)
10852  addr_filters_gen = 1
10855  If Not parent Then
10858  If err Then Go to err_addr_filters
10863  err = security_perf_event_alloc(event)
10864  If err Then Go to err_callchain_buffer
10868  account_event(event)
10870  Return event
10872  err_callchain_buffer :
10873  If Not parent Then
10874  If sample_type & PERF_SAMPLE_CALLCHAIN Then put_callchain_buffers()
10877  err_addr_filters :
10878  kfree(addr_filter_ranges)
10880  err_per_task :
10881  exclusive_event_destroy(event)
10883  err_pmu :
10884  If destroy Then destroy(event)
10886  module_put(module)
10887  err_ns :
10888  If is_cgroup_event(event) Then perf_detach_cgroup(event)
10890  If ns Then put_pid_ns(ns)
10892  If target Then put_task_struct(target)
10894  kfree(event)
10896  Return ERR_PTR(err)
Caller
NameDescribe
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