Skip to content

Commit

Permalink
[arch/um] adding get_cycles function (assumes host is x86_64).
Browse files Browse the repository at this point in the history
The UM arch doesn't allow to use the clock cycle counter,
as it is architecture-dependent. This hack borrows the rdtsc
function from x86_64 architecture.
  • Loading branch information
armfazh committed Dec 5, 2023
1 parent b910350 commit 75535bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions crypto/tcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ static int test_ahash_jiffies(struct ahash_request *req, int blen,
static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
char *out)
{
const int NUM_ITERATIONS = 1 << 10;
unsigned long cycles = 0;
int ret, i;

Expand All @@ -782,7 +783,7 @@ static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
}

/* The real thing. */
for (i = 0; i < 8; i++) {
for (i = 0; i < NUM_ITERATIONS; i++) {
cycles_t start, end;

start = get_cycles();
Expand All @@ -801,7 +802,7 @@ static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
return ret;

pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
cycles / 8, cycles / (8 * blen));
cycles / NUM_ITERATIONS, cycles / (NUM_ITERATIONS * blen));

return 0;
}
Expand Down
4 changes: 3 additions & 1 deletion include/asm-generic/timex.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ typedef unsigned long cycles_t;
#ifndef get_cycles
static inline cycles_t get_cycles(void)
{
return 0;
unsigned long low, high;
asm volatile("rdtsc" : "=a"(low), "=d"(high));
return (high<<32) | low;
}
#endif

Expand Down

0 comments on commit 75535bf

Please sign in to comment.