Skip to content
This repository was archived by the owner on Feb 22, 2025. It is now read-only.

Commit 5becefa

Browse files
committed
docs: Sync with upstream
1 parent 4b66a57 commit 5becefa

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

docs/master.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,11 @@ <h2 id="_functions">Functions</h2>
18941894
<td class="tableblock halign-left valign-top"><p class="tableblock">Sync</p></td>
18951895
</tr>
18961896
<tr>
1897+
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="#functions-percpu-kaddr"><code>percpu_kaddr(const string name [, int cpu])</code></a></p></td>
1898+
<td class="tableblock halign-left valign-top"><p class="tableblock">Resolve percpu kernel symbol name</p></td>
1899+
<td class="tableblock halign-left valign-top"><p class="tableblock">Sync</p></td>
1900+
</tr>
1901+
<tr>
18971902
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="#functions-print"><code>print(&#8230;&#8203;)</code></a></p></td>
18981903
<td class="tableblock halign-left valign-top"><p class="tableblock">Print a non-map value with default formatting</p></td>
18991904
<td class="tableblock halign-left valign-top"><p class="tableblock">Async</p></td>
@@ -2570,6 +2575,51 @@ <h3 id="functions-path">path</h3>
25702575
</div>
25712576
</div>
25722577
<div class="sect2">
2578+
<h3 id="functions-percpu-kaddr">percpu_kaddr</h3>
2579+
<div class="ulist">
2580+
<div class="title">variants</div>
2581+
<ul>
2582+
<li>
2583+
<p><code>void *percpu_kaddr(const string name)</code></p>
2584+
</li>
2585+
<li>
2586+
<p><code>void *percpu_kaddr(const string name, int cpu)</code></p>
2587+
</li>
2588+
</ul>
2589+
</div>
2590+
<div class="paragraph">
2591+
<p><strong>sync</strong></p>
2592+
</div>
2593+
<div class="paragraph">
2594+
<p>Get the address of the percpu kernel symbol <code>name</code> for CPU <code>cpu</code>. When <code>cpu</code> is
2595+
omitted, the current CPU is used.</p>
2596+
</div>
2597+
<div class="listingblock">
2598+
<div class="content">
2599+
<pre>interval:s:1 {
2600+
$proc_cnt = percpu_kaddr("process_counts");
2601+
printf("% processes are running on CPU %d\n", *$proc_cnt, cpu);
2602+
}</pre>
2603+
</div>
2604+
</div>
2605+
<div class="paragraph">
2606+
<p>The second variant may return NULL if <code>cpu</code> is higher than the number of
2607+
available CPUs. Therefore, it is necessary to perform a NULL-check on the result
2608+
when accessing fields of the pointed structure, otherwise the BPF program will
2609+
be rejected.</p>
2610+
</div>
2611+
<div class="listingblock">
2612+
<div class="content">
2613+
<pre>interval:s:1 {
2614+
$runqueues = (struct rq *)percpu_kaddr("runqueues", 0);
2615+
if ($runqueues != 0) { // The check is mandatory here
2616+
print($runqueues-&gt;nr_running);
2617+
}
2618+
}</pre>
2619+
</div>
2620+
</div>
2621+
</div>
2622+
<div class="sect2">
25732623
<h3 id="functions-print">print</h3>
25742624
<div class="ulist">
25752625
<div class="title">variants</div>

src/docs/master.adoc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,10 @@ Tracing block I/O sizes > 0 bytes
13641364
| Return full path
13651365
| Sync
13661366

1367+
| <<functions-percpu-kaddr, `percpu_kaddr(const string name [, int cpu])`>>
1368+
| Resolve percpu kernel symbol name
1369+
| Sync
1370+
13671371
| <<functions-print, `print(...)`>>
13681372
| Print a non-map value with default formatting
13691373
| Async
@@ -1846,6 +1850,39 @@ the path will be clamped by `size` otherwise `BPFTRACE_MAX_STRLEN` is used.
18461850

18471851
This function can only be used by functions that are allowed to, these functions are contained in the `btf_allowlist_d_path` set in the kernel.
18481852

1853+
[#functions-percpu-kaddr]
1854+
=== percpu_kaddr
1855+
1856+
.variants
1857+
* `void *percpu_kaddr(const string name)`
1858+
* `void *percpu_kaddr(const string name, int cpu)`
1859+
1860+
*sync*
1861+
1862+
Get the address of the percpu kernel symbol `name` for CPU `cpu`. When `cpu` is
1863+
omitted, the current CPU is used.
1864+
1865+
----
1866+
interval:s:1 {
1867+
$proc_cnt = percpu_kaddr("process_counts");
1868+
printf("% processes are running on CPU %d\n", *$proc_cnt, cpu);
1869+
}
1870+
----
1871+
1872+
The second variant may return NULL if `cpu` is higher than the number of
1873+
available CPUs. Therefore, it is necessary to perform a NULL-check on the result
1874+
when accessing fields of the pointed structure, otherwise the BPF program will
1875+
be rejected.
1876+
1877+
----
1878+
interval:s:1 {
1879+
$runqueues = (struct rq *)percpu_kaddr("runqueues", 0);
1880+
if ($runqueues != 0) { // The check is mandatory here
1881+
print($runqueues->nr_running);
1882+
}
1883+
}
1884+
----
1885+
18491886
[#functions-print]
18501887
=== print
18511888

0 commit comments

Comments
 (0)