Skip to content

Progress64 benchmarks #850

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

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions benchmarks/progress64/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# How to generate LLVM files with Inline Asm with Progress64

Choose a reason for hiding this comment

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

@ThomasHaas can you try this on your arm machine to check the documentation is correct?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ThomasHaas can you try this on your arm machine to check the documentation is correct?

rwlock.c doesn't compile because it misses definitions for the shared variables.

For seqlock.c I get this error:

/Users/thomashaas/ExternalTools/progress64/src/arch/ldxstx.h:223:24: error: controlling expression type 'uintptr_t *' (aka 'unsigned long *') not compatible with any generic association type
    return (void *)ldx((uintptr_t *)var, mm);
                       ^~~~~~~~~~~~~~~~
/Users/thomashaas/ExternalTools/progress64/src/arch/ldxstx.h:203:11: note: expanded from macro 'ldx'
_Generic((var), \
          ^~~
/Users/thomashaas/ExternalTools/progress64/src/arch/ldxstx.h:227:16: error: controlling expression type 'uintptr_t *' (aka 'unsigned long *') not compatible with any generic association type
    return stx((uintptr_t *)var, (uintptr_t)val, mm);

And a bunch of warnings that the assembly uses wrong register sizes:

/Users/thomashaas/ExternalTools/progress64/src/arch/ldxstx.h:195:27: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]
                   : "r" (neu), "r" (var)
                          ^
/Users/thomashaas/ExternalTools/progress64/src/arch/ldxstx.h:193:35: note: use constraint modifier "w"
    __asm volatile("stxp %w0, %1, %H1, [%2]"
                                  ^~~
                                  %wH1

These are all errors/warnings inside progress64, so I don't know how much we can do about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as Clang complains at times when GCC does not , in order to make that work I had to tweak some lines in the file which contains the inline asm

Choose a reason for hiding this comment

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

This is a huge red flag. We should keep changes to a minimal and if changes are indeed needed we need to

  • provide a patch so someone else can regenerate the llvm files if needed
  • document why the change is indeed needed


You need to clone [ARM-software/progress64](https://github.com/ARM-software/progress64).

In this case you have to generate the clients to leverage the API on your own.

Then, follow this pattern :
```
clang <Includes> <custom flags> -S -emit-llvm <file_path.c>
```
The Includes should contain :
1. path to progress64/include
2. path to progress64/src

The Custom flags should be set up accordingly to your client. In some cases, if you do not get inline asm, try to add :
1. ```-U__ARM_FEATURE_ATOMICS``` to force the compiler to avoid including the builtins

A valid example would therefore be, from root of progress64 :
```
clang -I <path_to_progress64>/include -I <path_to_progress64>/src -S -emit-llvm benchmarks/progress64/rwlock.c
```
34 changes: 34 additions & 0 deletions benchmarks/progress64/rwlock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <pthread.h>
#include <assert.h>
#include "p64_rwlock.c"

#define NTHREADS 3


void *run(void *arg) {
p64_rwlock_acquire_wr(&lock);
x++;
y++;
p64_rwlock_release_wr(&lock);
return NULL;
}

int main() {

Choose a reason for hiding this comment

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

This is not a good test for a read-write lock. Take a look to this

Copy link
Collaborator

Choose a reason for hiding this comment

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

It doesn't even comile, no? Where are lock, x, y defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah! I think I added the definition of those two in the src file, adding that now

pthread_t threads[NTHREADS];
p64_rwlock_init(&lock);

for (int i = 0; i < NTHREADS; i++) {
if (pthread_create(&threads[i], NULL, run, (void *)(long)i) != 0) {
exit(EXIT_FAILURE);
}
}

for (int i = 0; i < NTHREADS; i++) {
if (pthread_join(threads[i], NULL) != 0) {
exit(EXIT_FAILURE);
}
}

assert(x == NTHREADS && y == NTHREADS);
return 0;
}
57 changes: 57 additions & 0 deletions benchmarks/progress64/seqlock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <assert.h>
#include <pthread.h>
#include "p64_rwsync.c"

typedef struct {
int x;
int y;
} shared_data_t;

p64_rwsync_t sync;
shared_data_t data;

void *writer(void *arg) {
p64_rwsync_acquire_wr(&sync);
data.x++;
data.y++;
p64_rwsync_release_wr(&sync);
return NULL;
}

void *reader(void *arg) {
shared_data_t local;
p64_rwsync_read(&sync, &local, &data, sizeof(local));
return NULL;
}

int main(void) {

Choose a reason for hiding this comment

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

Why is this a good test for seqlock? Take a look to this. We should definitely use more than a single writer and a single reader.

pthread_t writers[2], readers[2];
p64_rwsync_init(&sync);
data.x = 0;
data.y = 0;

for (int i = 0; i < 2; i++) {
if (pthread_create(&writers[i], NULL, writer, NULL) != 0) {
exit(EXIT_FAILURE);
}
}
for (int i = 0; i < 2; i++) {
if (pthread_create(&readers[i], NULL, reader, NULL) != 0) {
exit(EXIT_FAILURE);
}
}

for (int i = 0; i < 2; i++) {
if (pthread_join(writers[i], NULL) != 0) {
exit(EXIT_FAILURE);
}
}

for (int i = 0; i < 2; i++) {
if (pthread_join(readers[i], NULL) != 0) {
exit(EXIT_FAILURE);
}
}
assert(data.x == 2 && data.y == 2);
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.dat3m.dartagnan.asm.armv8.progress64;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.EnumSet;

import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.sosy_lab.common.ShutdownManager;
import org.sosy_lab.common.configuration.Configuration;
import org.sosy_lab.common.configuration.InvalidConfigurationException;
import org.sosy_lab.common.log.BasicLogManager;
import org.sosy_lab.java_smt.SolverContextFactory;
import org.sosy_lab.java_smt.api.SolverContext;

import com.dat3m.dartagnan.configuration.Arch;
import static com.dat3m.dartagnan.configuration.Property.PROGRAM_SPEC;
import static com.dat3m.dartagnan.configuration.Property.TERMINATION;
import com.dat3m.dartagnan.encoding.ProverWithTracker;
import com.dat3m.dartagnan.parsers.cat.ParserCat;
import com.dat3m.dartagnan.parsers.program.ProgramParser;
import com.dat3m.dartagnan.program.Program;
import static com.dat3m.dartagnan.utils.ResourceHelper.getRootPath;
import static com.dat3m.dartagnan.utils.ResourceHelper.getTestResourcePath;
import com.dat3m.dartagnan.utils.Result;
import static com.dat3m.dartagnan.utils.Result.PASS;
import com.dat3m.dartagnan.verification.VerificationTask;
import com.dat3m.dartagnan.verification.solving.AssumeSolver;
import com.dat3m.dartagnan.verification.solving.RefinementSolver;
import com.dat3m.dartagnan.wmm.Wmm;

@RunWith(Parameterized.class)
public class AsmProgress64Armv8Test {

private final String modelPath = getRootPath("cat/aarch64.cat");
private final String programPath;
private final int bound;
private final Result expected;

public AsmProgress64Armv8Test (String file, int bound, Result expected) {
this.programPath = getTestResourcePath("asm/armv8/progress64/" + file + ".ll");
this.bound = bound;
this.expected = expected;
}

@Parameterized.Parameters(name = "{index}: {0}, {1}, {2}")
public static Iterable<Object[]> data() throws IOException {
return Arrays.asList(new Object[][]{
{"rwlock", 1, PASS},
{"seqlock", 3, PASS},
});
}

@Test
public void testAllSolvers() throws Exception {
try (SolverContext ctx = mkCtx(); ProverWithTracker prover = mkProver(ctx)) {
assertEquals(expected, RefinementSolver.run(ctx, prover, mkTask()).getResult());
}
try (SolverContext ctx = mkCtx(); ProverWithTracker prover = mkProver(ctx)) {
assertEquals(expected, AssumeSolver.run(ctx, prover, mkTask()).getResult());
}
}

private SolverContext mkCtx() throws InvalidConfigurationException {
Configuration cfg = Configuration.builder().build();
return SolverContextFactory.createSolverContext(
cfg,
BasicLogManager.create(cfg),
ShutdownManager.create().getNotifier(),
SolverContextFactory.Solvers.YICES2);
}

private ProverWithTracker mkProver(SolverContext ctx) {
return new ProverWithTracker(ctx, "", SolverContext.ProverOptions.GENERATE_MODELS);
}

private VerificationTask mkTask() throws Exception {
VerificationTask.VerificationTaskBuilder builder = VerificationTask.builder()
.withConfig(Configuration.builder().build())
.withBound(bound)
.withTarget(Arch.ARM8);
Program program = new ProgramParser().parse(new File(programPath));
Wmm mcm = new ParserCat().parse(new File(modelPath));
return builder.build(program, mcm, EnumSet.of(TERMINATION, PROGRAM_SPEC));
}
}
Loading