Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address "make dudect more portable?" #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

itzmeanjan
Copy link
Contributor

Adds support for running dudect -based constant-time tests on more targets i.e. aarch64 (running Linux kernel), Apple Silicon and more non-x86_64 targets.

Partially addresses #33.

@oreparaz
Copy link
Owner

oreparaz commented Jan 25, 2024

This is great @itzmeanjan . Thank you. Can you please list here the targets in which you tested it? (Maybe the test should be run test.py?)

I'll also test in a bunch of hardware and report back here.

@itzmeanjan
Copy link
Contributor Author

Can you please list here the targets in which you tested it? (Maybe the test should be run test.py?)

I've tested the patch, issuing make test -j, on following targets.

  1. 12th Gen Intel(R) Core(TM) i7-1260P : PASSED
$ uname -srm
Linux 6.5.0-15-generic x86_64 
  1. Apple M1 Max : PASSED
$ uname -srm
Darwin 23.2.0 arm64
  1. ARM Cortex-A72 (i.e. Raspberry Pi 4B) with Linux Kernel Module @ https://github.com/jerinjacobk/armv8_pmu_cycle_counter_el0 : PASSED except dudect_simple_O0 FAILING
$ uname -srm
Linux 6.5.0-1009-raspi aarch64

Copy link
Owner

@oreparaz oreparaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still need to test it in a couple of different changes but code review LGTM. Thanks a lot @itzmeanjan for this!!!

will merge soon after I get to test it

src/dudect.h Outdated
@@ -279,6 +289,61 @@ static inline int64_t cpucycles(void) {
return (int64_t)__rdtsc();
}

#elif defined __aarch64__ && defined __linux__
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#elif defined __aarch64__ && defined __linux__
#elif defined(__aarch64__) && defined(__linux__)

To enforce CPU to complete all pending memory access operations, appearing before PMCCTR_EL0, we issue a
*D*ata *S*ynchronization *B*arrier instruction right before reading CPU cycle counter.

Note, issuing PMCCTR_EL0 instruction from the userspace will probably result in panicing with
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to test this, but in any case: would we want to printf this helpful message in the _init function on aarch64? we can take it in another PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think we should notify the user in some way that they are expected to do something special for this target. How do you feel about using #warning "...", which emits a warning message during program compilation time also ? See https://en.cppreference.com/w/c/preprocessor/error

src/dudect.h Outdated
return (int64_t)val;
}

#elif defined __APPLE__
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#elif defined __APPLE__
#elif defined(__APPLE__)

Copy link
Contributor Author

@itzmeanjan itzmeanjan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make suggested changes and I've added one/ two comments.

To enforce CPU to complete all pending memory access operations, appearing before PMCCTR_EL0, we issue a
*D*ata *S*ynchronization *B*arrier instruction right before reading CPU cycle counter.

Note, issuing PMCCTR_EL0 instruction from the userspace will probably result in panicing with
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think we should notify the user in some way that they are expected to do something special for this target. How do you feel about using #warning "...", which emits a warning message during program compilation time also ? See https://en.cppreference.com/w/c/preprocessor/error

src/dudect.h Outdated
Comment on lines 329 to 343
/*
Returns approximate measurement of CPU time consumed by the calling process (i.e., CPU time
consumed by all threads in the process).

See https://www.man7.org/linux/man-pages/man3/clock_gettime.3.html
*/
static inline int64_t cpucycles(void) {
const clockid_t clock_id = CLOCK_PROCESS_CPUTIME_ID;
struct timespec ts = {0};

(void)clock_gettime(clock_id, &ts);

const uint64_t ns = (uint64_t)ts.tv_sec * (uint64_t)1e9 + (uint64_t)ts.tv_nsec;
return (int64_t)ns;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to get rid of this, this is giving me way too many false positives - too much in consistency. I'd just write a #error "..." with a message, which should say we don't yet support this target.

… and wider spectrum of non-x86_64 targets

Signed-off-by: Anjan Roy <[email protected]>
@itzmeanjan
Copy link
Contributor Author

👋 @oreparaz can we merge this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants