Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2048 → Rev 2050

/trunk/kernel/generic/include/func.h
48,6 → 48,7
extern int strncmp(const char *src, const char *dst, size_t len);
extern void strncpy(char *dest, const char *src, size_t len);
extern unative_t atoi(const char *text);
extern void order(const uint64_t val, uint64_t *rv, char *suffix);
 
#endif
 
/trunk/kernel/generic/src/console/cmd.c
117,6 → 117,25
.argc = 1,
.argv = test_argv
};
 
static int cmd_bench(cmd_arg_t *argv);
static cmd_arg_t bench_argv[] = {
{
.type = ARG_TYPE_STRING,
.buffer = test_buf,
.len = sizeof(test_buf)
},
{
.type = ARG_TYPE_INT,
}
};
static cmd_info_t bench_info = {
.name = "bench",
.description = "Run kernel test as benchmark.",
.func = cmd_bench,
.argc = 2,
.argv = bench_argv
};
#endif
 
/* Data and methods for 'description' command. */
411,6 → 430,7
#ifdef CONFIG_TEST
&tests_info,
&test_info,
&bench_info,
#endif
NULL
};
871,7 → 891,7
interrupts_restore(ipl);
/* Execute the test */
char * ret = test->entry();
char * ret = test->entry(false);
/* Update and read thread accounting */
ipl = interrupts_disable();
880,7 → 900,11
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
printf("Time: %llu cycles\n", dt);
uint64_t cycles;
char suffix;
order(dt, &cycles, &suffix);
printf("Time: %llu%c cycles\n", cycles, suffix);
if (ret == NULL) {
printf("Test passed\n");
891,6 → 915,72
return false;
}
 
static bool run_bench(const test_t *test, const uint32_t cnt)
{
uint32_t i;
bool ret = true;
uint64_t cycles;
char suffix;
if (cnt < 1)
return true;
uint64_t *data = malloc(sizeof(uint64_t) * cnt, 0);
if (data == NULL) {
printf("Error allocating memory for statistics\n");
return false;
}
for (i = 0; i < cnt; i++) {
printf("%s (%d/%d) ... ", test->name, i + 1, cnt);
/* Update and read thread accounting
for benchmarking */
ipl_t ipl = interrupts_disable();
spinlock_lock(&TASK->lock);
uint64_t t0 = task_get_accounting(TASK);
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
/* Execute the test */
char * ret = test->entry(true);
/* Update and read thread accounting */
ipl = interrupts_disable();
spinlock_lock(&TASK->lock);
uint64_t dt = task_get_accounting(TASK) - t0;
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
if (ret != NULL) {
printf("%s\n", ret);
ret = false;
break;
}
data[i] = dt;
order(dt, &cycles, &suffix);
printf("OK (%llu%c cycles)\n", cycles, suffix);
}
if (ret) {
printf("\n");
uint64_t sum = 0;
for (i = 0; i < cnt; i++) {
sum += data[i];
}
order(sum / (uint64_t) cnt, &cycles, &suffix);
printf("Average\t\t%llu%c\n", cycles, suffix);
}
free(data);
return ret;
}
 
/** Command for returning kernel tests
*
* @param argv Argument vector.
926,6 → 1016,34
return 1;
}
 
/** Command for returning kernel tests as benchmarks
*
* @param argv Argument vector.
*
* return Always 1.
*/
int cmd_bench(cmd_arg_t *argv)
{
test_t *test;
uint32_t cnt = argv[1].intval;
bool fnd = false;
for (test = tests; test->name != NULL; test++) {
if (strcmp(test->name, argv->buffer) == 0) {
fnd = true;
run_bench(test, cnt);
break;
}
}
if (!fnd)
printf("Unknown test\n");
 
return 1;
}
 
#endif
 
/** @}
/trunk/kernel/generic/src/proc/task.c
52,6 → 52,7
#include <print.h>
#include <lib/elf.h>
#include <errno.h>
#include <func.h>
#include <syscall/copy.h>
#include <console/klog.h>
 
391,21 → 392,10
spinlock_lock(&t->lock);
uint64_t cycles = task_get_accounting(t);
uint64_t cycles;
char suffix;
order(task_get_accounting(t), &cycles, &suffix);
if (cycles > 1000000000000000000LL) {
cycles = cycles / 1000000000000000000LL;
suffix = 'E';
} else if (cycles > 1000000000000LL) {
cycles = cycles / 1000000000000LL;
suffix = 'T';
} else if (cycles > 1000000LL) {
cycles = cycles / 1000000LL;
suffix = 'M';
} else
suffix = ' ';
printf("%-6lld %-10s %-3ld %#10zx %#10zx %9llu%c %7zd %6zd", t->taskid, t->name, t->context, t, t->as, cycles, suffix, t->refcount, atomic_get(&t->active_calls));
for (j = 0; j < IPC_MAX_PHONES; j++) {
if (t->phones[j].callee)
/trunk/kernel/generic/src/proc/thread.c
569,21 → 569,8
uint64_t cycles;
char suffix;
order(t->cycles, &cycles, &suffix);
if (t->cycles > 1000000000000000000LL) {
cycles = t->cycles / 1000000000000000000LL;
suffix = 'E';
} else if (t->cycles > 1000000000000LL) {
cycles = t->cycles / 1000000000000LL;
suffix = 'T';
} else if (t->cycles > 1000000LL) {
cycles = t->cycles / 1000000LL;
suffix = 'M';
} else {
cycles = t->cycles;
suffix = ' ';
}
printf("%-6zd %-10s %#10zx %-8s %#10zx %-3ld %#10zx %#10zx %9llu%c ", t->tid, t->name, t, thread_states[t->state], t->task, t->task->context, t->thread_code, t->kstack, cycles, suffix);
if (t->cpu)
/trunk/kernel/generic/src/lib/func.c
221,5 → 221,23
return result;
}
 
 
void order(const uint64_t val, uint64_t *rv, char *suffix)
{
if (val > 1000000000000000000LL) {
*rv = val / 1000000000000000000LL;
*suffix = 'E';
} else if (val > 1000000000000LL) {
*rv = val / 1000000000000LL;
*suffix = 'T';
} else if (val > 1000000LL) {
*rv = val / 1000000LL;
*suffix = 'M';
} else {
*rv = val;
*suffix = ' ';
}
}
 
/** @}
*/