2024-07-30 17:15:40 +02:00
|
|
|
/* Copyright (c) 2024 Barcelona Supercomputing Center (BSC)
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later */
|
|
|
|
|
|
|
|
#include <nosv.h>
|
|
|
|
#include <nosv/affinity.h>
|
|
|
|
#include <stdatomic.h>
|
|
|
|
#include <unistd.h>
|
2024-07-31 11:53:01 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2024-07-30 17:15:40 +02:00
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "compat.h"
|
|
|
|
|
|
|
|
int done = 0;
|
2024-07-31 11:53:01 +02:00
|
|
|
unsigned long ncs = 0;
|
|
|
|
unsigned long nflush = 0;
|
2024-07-30 17:15:40 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
task_run(nosv_task_t task)
|
|
|
|
{
|
|
|
|
UNUSED(task);
|
|
|
|
|
|
|
|
struct timespec one_ns = { .tv_sec = 0, .tv_nsec = 1 };
|
|
|
|
|
2024-07-31 11:53:01 +02:00
|
|
|
for (unsigned long i = 1; i <= ncs; i++) {
|
|
|
|
nanosleep(&one_ns, NULL);
|
|
|
|
if (i % nflush == 0) {
|
2024-07-31 14:47:12 +02:00
|
|
|
info("flushing at %lu", i);
|
2024-07-31 11:53:01 +02:00
|
|
|
if (nosv_waitfor(1, NULL) != 0)
|
|
|
|
die("nosv_waitfor failed");
|
|
|
|
}
|
2024-07-30 17:15:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
done = 1;
|
|
|
|
}
|
|
|
|
|
2024-07-31 11:53:01 +02:00
|
|
|
int main(int argc, char *argv[])
|
2024-07-30 17:15:40 +02:00
|
|
|
{
|
2024-07-31 11:53:01 +02:00
|
|
|
if (argc != 3)
|
|
|
|
die("usage: %s <num-cs> <num-flush>\n", argv[0]);
|
|
|
|
|
|
|
|
ncs = (unsigned long) atol(argv[1]);
|
|
|
|
nflush = (unsigned long) atol(argv[2]);
|
|
|
|
|
2024-07-30 17:15:40 +02:00
|
|
|
if (nosv_init())
|
|
|
|
die("nosv_init failed");
|
|
|
|
|
|
|
|
nosv_task_type_t task_type;
|
|
|
|
if (nosv_type_init(&task_type, task_run, NULL, NULL, "task", NULL, NULL, NOSV_TYPE_INIT_NONE))
|
|
|
|
die("nosv_type_init failed");
|
|
|
|
|
|
|
|
nosv_task_t task;
|
|
|
|
if (nosv_create(&task, task_type, 0, NOSV_CREATE_NONE))
|
|
|
|
die("nosv_create failed");
|
|
|
|
|
|
|
|
if (nosv_submit(task, NOSV_SUBMIT_IMMEDIATE))
|
|
|
|
die("nosv_submit failed");
|
|
|
|
|
|
|
|
/* Wait for the task to finish */
|
|
|
|
while (!done)
|
|
|
|
sleep_us(10000);
|
|
|
|
|
|
|
|
if (nosv_destroy(task, NOSV_DESTROY_NONE))
|
|
|
|
die("nosv_destroy failed");
|
|
|
|
|
|
|
|
if (nosv_type_destroy(task_type, NOSV_TYPE_DESTROY_NONE))
|
|
|
|
die("nosv_type_destroy failed");
|
|
|
|
|
|
|
|
if (nosv_shutdown())
|
|
|
|
die("nosv_shutdown failed");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|