forked from amazonlinux/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: add a benchmark for smp_processor_id()
This module can be used to benchmark different implementations of smp_processor_id(); Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
- Loading branch information
1 parent
18daea7
commit 77d3fdd
Showing
4 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# SPDX-License-Identifier: GPL-2.0-only | ||
|
||
obj-$(CONFIG_SAMPLE_SMP_PROCESSOR_ID) += smp_processor_id.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
|
||
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
|
||
#include <linux/ktime.h> | ||
#include <linux/module.h> | ||
#include <linux/smp.h> | ||
|
||
/* | ||
* Arbitrary large value chosen to be sufficiently large to minimize noise but | ||
* sufficiently small to complete quickly. | ||
*/ | ||
static unsigned int nr_function_calls = 1000000; | ||
module_param(nr_function_calls, uint, 0); | ||
MODULE_PARM_DESC(nr_function_calls, "How many times to call the smp_processor_id()"); | ||
|
||
static noinline int get_cpu_id(void) | ||
{ | ||
return smp_processor_id(); | ||
} | ||
|
||
static int __init smp_processor_id_sample_init(void) | ||
{ | ||
volatile int cpu; | ||
ktime_t start, end; | ||
u64 period; | ||
|
||
start = ktime_get(); | ||
for (unsigned int i = 0; i < nr_function_calls; i++) | ||
cpu = get_cpu_id(); | ||
end = ktime_get(); | ||
|
||
period = ktime_to_ns(ktime_sub(end, start)); | ||
|
||
pr_info("Attempted %u calls to %ps in %lluns (%lluns / call)\n", | ||
nr_function_calls, get_cpu_id, | ||
period, div_u64(period, nr_function_calls)); | ||
|
||
/* | ||
* The benchmark completed successfully, but there's no reason to keep | ||
* the module around. Return an error do the user doesn't have to | ||
* manually unload the module. | ||
*/ | ||
return -EINVAL; | ||
} | ||
module_init(smp_processor_id_sample_init); | ||
|
||
static void __exit smp_processor_id_sample_exit(void) | ||
{ | ||
} | ||
module_exit(smp_processor_id_sample_exit); | ||
|
||
MODULE_AUTHOR("Puranjay Mohan"); | ||
MODULE_DESCRIPTION("Benchmark for smp_processor_id function"); | ||
MODULE_LICENSE("GPL"); |