Skip to content

Commit

Permalink
(litmus tests) replace requires_* with generic requires check
Browse files Browse the repository at this point in the history
  • Loading branch information
bensimner committed Jan 2, 2025
1 parent ddf6cfe commit 8d19fe7
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 19 deletions.
17 changes: 14 additions & 3 deletions inc/arm_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ enum arm_feature {

/* Tracing */
FEAT_TRBE,

/* Atomics etc */
FEAT_LSE,

NO_ARM_FEATURES,
};

/** struct arch_feature_matrix - Arch-specific implementation state for each feature.
Expand All @@ -31,19 +36,20 @@ enum arm_feature {
* typically containing the implemented version.
*/
struct arch_feature_matrix {
u8 features[1+FEAT_TRBE];
u8 features[NO_ARM_FEATURES];
};

/* Arm ID registers */
#define ISAR0 read_sysreg(ID_AA64ISAR0_EL1)
#define DFR0 read_sysreg(ID_AA64DFR0_EL1)
#define PFR0 read_sysreg(ID_AA64PFR0_EL1)
#define MMFR0 read_sysreg(ID_AA64MMFR0_EL1)
#define MMFR1 read_sysreg(ID_AA64MMFR1_EL1)
#define MIDR read_sysreg(MIDR_EL1)

/* instruction set attribute register(s) */
#define ISAR0_FIELD_BF16 BITMASK(47, 44)
#define ISAR0_FIELD_BF16_LSB 44
#define ISAR0_FIELD_ATOMIC 23, 20
#define ISAR0_FIELD_ATOMIC_LSB 20

/* memory model feature register(s) */
#define MMFR0_FIELD_ASIDBits 7, 4
Expand Down Expand Up @@ -85,4 +91,9 @@ struct arm_implementation {
void arch_read_implementation(struct arm_implementation* impl_out);
bool arch_implementation_eq(struct arm_implementation* lhs, struct arm_implementation* rhs);

static inline bool has_aarch64_feat_lse(void)
{
return arch_has_feature(FEAT_LSE);
}

#endif /* ARM_FEAT_H */
15 changes: 12 additions & 3 deletions inc/litmus/litmus_test_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ typedef struct
arch_model_status_t allowed;
} arch_allow_st;

enum litmus_prereq_feature
{
REQUIRES_DEBUG = 1 << 1,
REQUIRES_PERF = 1 << 2,
REQUIRES_PGTABLE = 1 << 3,
REQUIRES_ARM_AARCH64_FEAT_LSE = 1 << 4, /* Arm atomics */
};

/**
* definition of a litmus test
*
Expand Down Expand Up @@ -168,9 +176,10 @@ typedef struct
u32*** thread_sync_handlers;

/** whether the test requires any special options to be enabled */
u8 requires_pgtable; /* requires --pgtable */
u8 requires_perf; /* requires --perf */
u8 requires_debug; /* requires -d */
// u8 requires_pgtable; /* requires --pgtable */
// u8 requires_perf; /* requires --perf */
// u8 requires_debug; /* requires -d */
enum litmus_prereq_feature requires;

/* annotate the test with whether it's allowed for certain models or not
* e.g.
Expand Down
3 changes: 3 additions & 0 deletions lib/arch/feat.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ u8 arch_feature_version(enum arm_feature id) {
return BIT_SLICE(DFR0, DFR0_FIELD_PMUVer);
case FEAT_TRBE:
return BIT_SLICE(DFR0, DFR0_FIELD_TraceVer);
case FEAT_LSE:
return BIT_SLICE(ISAR0, ISAR0_FIELD_ATOMIC);
default:
unreachable();
}
Expand All @@ -23,6 +25,7 @@ void arch_read_feature_matrix(struct arch_feature_matrix* m_out) {
m_out->features[FEAT_RAS] = arch_feature_version(FEAT_RAS);
m_out->features[FEAT_PMUv3] = arch_feature_version(FEAT_PMUv3);
m_out->features[FEAT_TRBE] = arch_feature_version(FEAT_TRBE);
m_out->features[FEAT_LSE] = arch_feature_version(FEAT_LSE);
}

bool arch_has_feature(enum arm_feature id) {
Expand Down
4 changes: 2 additions & 2 deletions lib/litmus_test/litmus_test_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

static void sanity_check_test(const litmus_test_t* cfg, int no_runs, int runs_in_batch) {
/* we have 1+MAX_ASID ASIDs */
if (cfg->requires_pgtable && runs_in_batch > 1 + MAX_ASID)
if ((cfg->requires & REQUIRES_PGTABLE) && runs_in_batch > 1 + MAX_ASID)
fail("cannot have more than the number of possible ASIDs (%ld) as runs in a batch with --pgtable.\n", 1 + MAX_ASID);
}

Expand Down Expand Up @@ -181,7 +181,7 @@ u64 ctx_initial_heap_value(test_ctx_t* ctx, run_idx_t idx) {

u64 asid_from_run_count(test_ctx_t* ctx, run_count_t r) {
/* reserve ASID 0 for harness */
if (ctx->cfg->requires_pgtable)
if (ctx->cfg->requires & REQUIRES_PGTABLE)
return 1 + (r % ctx->batch_size);
else
/* if pgtables are enabled, but the test does not require editing them
Expand Down
6 changes: 3 additions & 3 deletions litmus/help_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ void display_help_for_grp(const litmus_test_group* grp) {
const litmus_test_t* t = grp->tests[i];
printf(" %s", t->name);

if (t->requires_perf) {
if (t->requires & REQUIRES_PERF) {
printf(" (requires --perf)");
}

if (t->requires_pgtable) {
if (t->requires & REQUIRES_PGTABLE) {
printf(" (requires --pgtable)");
}

if (t->requires_debug) {
if (t->requires & REQUIRES_ARM_AARCH64_FEAT_LSE) {
printf(" (requires -d)");
}

Expand Down
4 changes: 2 additions & 2 deletions litmus/linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def check_init_count(lit):
def check_requires_pgtable(lit):
code = lit['c_code']

req_pgtable_re = r'\.requires_pgtable\s*=\s*1'
req_pgtable_re = r'\.requires\s*=\s*REQUIRES_PGTABLE'
m_req_pgtable = re.search(req_pgtable_re, code, re.MULTILINE)

# look for things that look like it requires the MMU enabled:
Expand All @@ -262,7 +262,7 @@ def check_requires_pgtable(lit):
m_mmu_enable_check = re.search(mmu_enable_check_re, code, re.MULTILINE)

if m_mmu_enable_check and not m_req_pgtable:
warn(lit, 'missing requires_pgtable=1?')
warn(lit, 'missing requires=REQUIRES_PGTABLE?')

def run_lint(linter, litmus):
if linter.__name__ in args.excl:
Expand Down
18 changes: 12 additions & 6 deletions litmus/main_match_and_run.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@
#include "frontend.h"

static void run_test_fn(const litmus_test_t* tst, u8 report_skip) {
if (tst->requires_perf && (!ENABLE_PERF_COUNTS)) {
if ((tst->requires & REQUIRES_PERF) && (! ENABLE_PERF_COUNTS)) {
if (report_skip)
warning(WARN_SKIP_TEST, "skipping \"%s\": requires --perf\n", tst->name);
printf("! skipping \"%s\": requires --perf\n", tst->name);
return;
}

if (tst->requires_pgtable && (!ENABLE_PGTABLE)) {
if ((tst->requires & REQUIRES_PGTABLE) && (! ENABLE_PGTABLE)) {
if (report_skip)
warning(WARN_SKIP_TEST, "skipping \"%s\": requires --pgtable\n", tst->name);
printf("! skipping \"%s\": requires --pgtable\n", tst->name);
return;
}

if (tst->requires_debug && (!DEBUG)) {
if ((tst->requires & REQUIRES_DEBUG) && (! DEBUG)) {
if (report_skip)
warning(WARN_SKIP_TEST, "skipping \"%s\": requires -d\n", tst->name);
printf("! skipping \"%s\": requires -d\n", tst->name);
return;
}

if ((tst->requires & REQUIRES_ARM_AARCH64_FEAT_LSE) && (! has_aarch64_feat_lse())) {
if (report_skip)
printf("! skipping \"%s\": requires -d\n", tst->name);
return;
}

Expand Down

0 comments on commit 8d19fe7

Please sign in to comment.