Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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

Name:perf_mmap

Proto:static int perf_mmap(struct file *file, struct vm_area_struct *vma)

Type:int

Parameter:

TypeParameterName
struct file *file
struct vm_area_struct *vma
5791  event = needed for tty driver, and maybe others
5793  user = current_user()
5795  struct ring_buffer * rb = NULL
5798  user_extra = 0 , extra = 0
5799  ret = 0 , flags = 0
5806  If cpu == -1 && inherit Then Return -EINVAL
5809  If Not (Flags, see mm.h. & VM_SHARED) Then Return -EINVAL
5812  ret = security_perf_event_read(event)
5813  If ret Then Return ret
5816  vma_size = The first byte after our end addresswithin vm_mm. - Our start address within vm_mm.
5818  If Offset (within vm_file) in PAGE_SIZEunits == 0 Then
5819  nr_pages = vma_size / PAGE_SIZE - 1
5820  Else
5828  If Not rb Then Return -EINVAL
5831  nr_pages = vma_size / PAGE_SIZE
5833  mutex_lock( & mmap_mutex)
5834  ret = -EINVAL
5836  rb = rb
5837  If Not rb Then Go to aux_unlock
5840  aux_offset = READ_ONCE(aux_offset)
5841  aux_size = READ_ONCE(aux_size)
5843  If aux_offset < perf_data_size(rb) + PAGE_SIZE Then Go to aux_unlock
5846  If aux_offset != Offset (within vm_file) in PAGE_SIZEunits << PAGE_SHIFT determines the page size Then Go to aux_unlock
5850  If rb_has_aux(rb) && aux_pgoff != Offset (within vm_file) in PAGE_SIZEunits Then Go to aux_unlock
5853  If aux_size != vma_size || aux_size != nr_pages * PAGE_SIZE Then Go to aux_unlock
5857  If rb_has_aux(rb) && aux_nr_pages != nr_pages Then Go to aux_unlock
5860  If Not s_power_of_2() - check if a value is a power of two*@n: the value to check* Determine whether some value is a power of two, where zero is* *not* considered a power of two.* Return: true if @n is a power of 2, otherwise false. Then Go to aux_unlock
5863  If Not atomic_inc_not_zero - increment unless the number is zero*@v: pointer of type atomic_t* Atomically increments @v by 1, if @v is non-zero.* Returns true if the increment was done. Then Go to aux_unlock
5866  If rb_has_aux(rb) Then
5868  ret = 0
5869  Go to unlock
5872  atomic_set( & aux_mmap_count, 1)
5873  user_extra = nr_pages
5875  Go to accounting
5882  If nr_pages != 0 && Not s_power_of_2() - check if a value is a power of two*@n: the value to check* Determine whether some value is a power of two, where zero is* *not* considered a power of two.* Return: true if @n is a power of 2, otherwise false. Then Return -EINVAL
5885  If vma_size != PAGE_SIZE * (1 + nr_pages) Then Return -EINVAL
5888  WARN_ON_ONCE(parent_ctx)
5889  again :
5890  mutex_lock( & mmap_mutex)
5891  If rb Then
5892  If nr_pages != nr_pages Then
5893  ret = -EINVAL
5894  Go to unlock
5904  Go to again
5907  Go to unlock
5910  user_extra = nr_pages + 1
5912  accounting :
5913  user_lock_limit = Minimum for 512 kiB + 1 user control page >> PAGE_SHIFT determines the page size - 10
5918  user_lock_limit *= num_online_cpus()
5920  user_locked = atomic_long_read( & locked_vm)
5926  If user_locked > user_lock_limit Then user_locked = user_lock_limit
5928  user_locked += user_extra
5930  If user_locked > user_lock_limit Then
5935  extra = user_locked - user_lock_limit
5936  user_extra -= extra
5939  lock_limit = rlimit(RLIMIT_MEMLOCK)
5940  lock_limit >>= PAGE_SHIFT determines the page size
5941  locked = atomic64_read( & pinned_vm) + extra
5943  If locked > lock_limit && perf_is_paranoid() && Not Check operation authority Then
5945  ret = -EPERM
5946  Go to unlock
5949  WARN_ON(!rb && rb)
5951  If Flags, see mm.h. & VM_WRITE Then flags |= Buffer handling
5954  If Not rb Then
5955  rb = rb_alloc(nr_pages, watermark ? wakeup_watermark : 0, cpu, flags)
5959  If Not rb Then
5960  ret = -ENOMEM
5961  Go to unlock
5964  atomic_set( & mmap_count, 1)
5965  mmap_user = get_current_user - Get the current task's user_struct* Get the user record of the current task, pinning it so that it can't go* away.()
5966  mmap_locked = extra
5968  ring_buffer_attach(event, rb)
5970  perf_event_init_userpage(event)
5971  Callers need to ensure there can be no nesting of this function, otherwise* the seqlock logic goes bad. We can not serialize this because the arch* code calls this from NMI context.
5972  Else
5973  ret = rb_alloc_aux(rb, event, Offset (within vm_file) in PAGE_SIZEunits , nr_pages, aux_watermark, flags)
5975  If Not ret Then aux_mmap_locked = extra
5979  unlock :
5980  If Not ret Then
5981  atomic_long_add(user_extra, & locked_vm)
5982  atomic64_add(extra, & pinned_vm)
5984  atomic_inc( & mmap_count)
5985  Else if rb Then
5986  atomic_dec( & mmap_count)
5988  aux_unlock :
5989  mutex_unlock - release the mutex*@lock: the mutex to be released* Unlock a mutex that has been locked by this task previously.* This function must not be used in interrupt context. Unlocking* of a not locked mutex is not allowed.
5995  Flags, see mm.h. |= Do not copy this vma on fork | Cannot expand with mremap() | Do not include in the core dump
5996  Function pointers to deal with this struct. = perf_mmap_vmops
5998  If event_mapped Then event_mapped(event, The address space we belong to. )
6001  Return ret