tools/testing/selftests/mqueue/mq_perf_tests.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/mqueue/mq_perf_tests.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/mqueue/mq_perf_tests.c
Extension
.c
Size
22072 bytes
Lines
755
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

struct test {
	char *desc;
	void (*func)(int *);
};

void const_prio(int *prio)
{
	return;
}

void inc_prio(int *prio)
{
	if (++*prio == mq_prio_max)
		*prio = 0;
}

void dec_prio(int *prio)
{
	if (--*prio < 0)
		*prio = mq_prio_max - 1;
}

void random_prio(int *prio)
{
	*prio = random() % mq_prio_max;
}

struct test test2[] = {
	{"\n\tTest #2a: Time send/recv message, queue full, constant prio\n",
		const_prio},
	{"\n\tTest #2b: Time send/recv message, queue full, increasing prio\n",
		inc_prio},
	{"\n\tTest #2c: Time send/recv message, queue full, decreasing prio\n",
		dec_prio},
	{"\n\tTest #2d: Time send/recv message, queue full, random prio\n",
		random_prio},
	{NULL, NULL}
};

/**
 * Tests to perform (all done with MSG_SIZE messages):
 *
 * 1) Time to add/remove message with 0 messages on queue
 * 1a) with constant prio
 * 2) Time to add/remove message when queue close to capacity:
 * 2a) with constant prio
 * 2b) with increasing prio
 * 2c) with decreasing prio
 * 2d) with random prio
 * 3) Test limits of priorities honored (double check _SC_MQ_PRIO_MAX)
 */
void *perf_test_thread(void *arg)
{
	char buff[MSG_SIZE];
	int prio_out;
	unsigned int prio_in;
	int i;
	clockid_t clock;
	pthread_t *t;
	struct timespec res, start, middle, end, send_total, recv_total;
	unsigned long long nsec;
	struct test *cur_test;

	t = &cpu_threads[0];
	printf("\n\tStarted mqueue performance test thread on CPU %d\n",
	       cpus_to_pin[0]);
	mq_prio_max = sysconf(_SC_MQ_PRIO_MAX);
	if (mq_prio_max == -1)
		shutdown(2, "sysconf(_SC_MQ_PRIO_MAX)", __LINE__);
	if (pthread_getcpuclockid(cpu_threads[0], &clock) != 0)
		shutdown(2, "pthread_getcpuclockid", __LINE__);

	if (clock_getres(clock, &res))
		shutdown(2, "clock_getres()", __LINE__);

	printf("\t\tMax priorities:\t\t\t%d\n", mq_prio_max);
	printf("\t\tClock resolution:\t\t%lu nsec%s\n", res.tv_nsec,
	       res.tv_nsec > 1 ? "s" : "");



	printf("\n\tTest #1: Time send/recv message, queue empty\n");
	printf("\t\t(%d iterations)\n", TEST1_LOOPS);
	prio_out = 0;
	send_total.tv_sec = 0;
	send_total.tv_nsec = 0;
	recv_total.tv_sec = 0;
	recv_total.tv_nsec = 0;
	for (i = 0; i < TEST1_LOOPS; i++)
		do_send_recv();

Annotation

Implementation Notes