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

Tools: Testbench: xt-testbench #6513

Merged
merged 4 commits into from
May 4, 2023

Conversation

singalsu
Copy link
Collaborator

@singalsu singalsu commented Nov 1, 2022

Now ready. see commit texts for description.

@btian1 btian1 self-requested a review November 2, 2022 01:34
tools/testbench/makefile-xcc Outdated Show resolved Hide resolved
tools/testbench/makefile-xcc Outdated Show resolved Hide resolved
src/arch/host/CMakeLists.txt Outdated Show resolved Hide resolved
@singalsu singalsu requested a review from fredoh9 November 3, 2022 09:41
@btian1
Copy link
Contributor

btian1 commented Nov 4, 2022

one more question is: where is the entry for this testbench?

@lgirdwood
Copy link
Member

one more question is: where is the entry for this testbench?

src/tools/testbench

@singalsu singalsu force-pushed the testbench_surgery branch 3 times, most recently from 661b239 to ed4a9a7 Compare November 10, 2022 15:45
@fredoh9 fredoh9 changed the title [DRAFT][WIP] Static testbench build and xt-testbench [SKIP CI][DRAFT][WIP] Static testbench build and xt-testbench Nov 10, 2022
src/audio/asrc/asrc.c Outdated Show resolved Hide resolved
src/arch/host/include/arch/debug/backtrace.h Outdated Show resolved Hide resolved
src/audio/module_adapter/CMakeLists.txt Outdated Show resolved Hide resolved
tools/testbench/include/alsa/sound/uapi/asoc.h Outdated Show resolved Hide resolved
tools/testbench/makefile-xcc Outdated Show resolved Hide resolved
tools/testbench/CMakeLists.txt Outdated Show resolved Hide resolved
tools/tplg_parser/tokens.c Outdated Show resolved Hide resolved
@singalsu singalsu force-pushed the testbench_surgery branch 2 times, most recently from b8fdb51 to 8142001 Compare February 28, 2023 16:15
@singalsu singalsu changed the title [SKIP CI][DRAFT][WIP] Static testbench build and xt-testbench Tools: Testbench: Static testbench build and xt-testbench Feb 28, 2023
scripts/rebuild-xt-testbench.sh Outdated Show resolved Hide resolved
src/arch/host/CMakeLists.txt Outdated Show resolved Hide resolved
src/arch/host/include/arch/debug/backtrace.h Outdated Show resolved Hide resolved
tools/test/audio/comp_run.sh Outdated Show resolved Hide resolved
@singalsu singalsu force-pushed the testbench_surgery branch from 8142001 to 3cad3f5 Compare March 3, 2023 17:31
@singalsu singalsu force-pushed the testbench_surgery branch from 3cad3f5 to aedaecf Compare March 7, 2023 11:31
@marc-hb

This comment was marked as outdated.

@singalsu
Copy link
Collaborator Author

singalsu commented Mar 8, 2023

Thanks @marc-hb the file DAI may be missing some DAI operation that fuzzer expects.

@singalsu singalsu force-pushed the testbench_surgery branch from aedaecf to 3c7dfd6 Compare March 8, 2023 09:34
Copy link
Collaborator

@lyakh lyakh left a comment

Choose a reason for hiding this comment

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

Do I understand it correctly, that we currently can run testbench tests on the host multi-threaded and after this PR we won't be able to do that any more? Cannot we keep both modes?

src/include/sof/schedule/ll_schedule.h Outdated Show resolved Hide resolved
src/include/sof/audio/component.h Outdated Show resolved Hide resolved
tools/testbench/topology.c Outdated Show resolved Hide resolved
tools/tplg_parser/tokens.c Outdated Show resolved Hide resolved
src/arch/host/include/arch/atomic.h Outdated Show resolved Hide resolved
@singalsu
Copy link
Collaborator Author

singalsu commented Mar 8, 2023

Do I understand it correctly, that we currently can run testbench tests on the host multi-threaded and after this PR we won't be able to do that any more? Cannot we keep both modes?

Yep, this is what it does... @lgirdwood can we restore the multi-threading with your work for alsa plugin so we could have both?

My idea is that I would get the improvements for topology parser and IPC simulation to xt-testbench from the plugin work. So this would be an intermediate step. Or wait to have both somehow.

@sys-pt1s
Copy link

sys-pt1s commented Apr 6, 2023

Can one of the admins verify this patch?

#if defined __XCC__
printf("Total execution cycles: %lu\n\n", (unsigned long)delta);
#else
printf("Total execution time: %lu us, %.2f x realtime\n\n",
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't double be %lf?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Double is overkill for this, I'll change the equation to float. The table https://cplusplus.com/reference/cstdio/printf/ suggests that L would be used for long double, while l seems to be for integers unless I'm misunderstanding it.

Copy link
Collaborator Author

@singalsu singalsu left a comment

Choose a reason for hiding this comment

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

I've now addressed review feedback, thanks for the comments!

@@ -86,7 +86,8 @@ struct tplg_context {
ptr = (struct snd_soc_tplg_hdr *)(ctx->tplg_base + ctx->tplg_offset); \
if (ptr->size != sizeof(*ptr)) { \
printf("%s %d hdr size mismatch 0x%x:0x%lx at offset %ld\n", \
__func__, __LINE__, ptr->size, sizeof(*ptr), \
__func__, __LINE__, ptr->size, \
(unsigned long)sizeof(*ptr), \
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changing 0x%lx to 0x%zx seems be OK for both gcc and xcc, I'll update the patch with it.

@@ -637,7 +651,11 @@ static int pipline_test(struct testbench_prm *tp)
dp_count, err);
break;
}
#if defined __XCC__
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, I've added functions to get time and cycles. The patch now also computes MCPS with file read/write consumption excluded.

printf("Total execution time: %zu us, %.2f x realtime\n\n",
delta, (double)((double)n_out / tp->channels_out / tp->fs_out) * 1000000 / delta);
#if defined __XCC__
printf("Total execution cycles: %lu\n\n", (unsigned long)delta);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, yes that works!

#if defined __XCC__
printf("Total execution cycles: %lu\n\n", (unsigned long)delta);
#else
printf("Total execution time: %lu us, %.2f x realtime\n\n",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Double is overkill for this, I'll change the equation to float. The table https://cplusplus.com/reference/cstdio/printf/ suggests that L would be used for long double, while l seems to be for integers unless I'm misunderstanding it.

@singalsu
Copy link
Collaborator Author

Now run of e.g. >> process_test('volume', 32, 32, 48000, 0, 'xt-run'); gives test result for MCPS

Input sample (frame) count: 326400 (163200)
Output sample (frame) count: 326400 (163200)
Total execution cycles: 18810961
File component cycles: 11272232
Pipeline cycles: 7538729
Pipeline MCPS: 2.22

@@ -602,10 +626,10 @@ static int pipline_test(struct testbench_prm *tp)
struct tplg_context ctx;
struct timespec ts;
struct timespec td0, td1;
uint64_t delta_t;
Copy link
Collaborator

Choose a reason for hiding this comment

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

long long for consistency?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, yes changed now!

@singalsu singalsu force-pushed the testbench_surgery branch from ffdb170 to d7cd418 Compare April 17, 2023 08:20
@singalsu singalsu requested a review from marc-hb April 17, 2023 08:21
Copy link
Collaborator

@marc-hb marc-hb left a comment

Choose a reason for hiding this comment

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

Caught one $TPLGFN typo, otherwise shell script changes LGTM

# Use topology from component test topologies
INFMT=s${BITS_IN}le
OUTFMT=s${BITS_OUT}le
TPLGFN=test-${DIRECTION}-ssp5-mclk-0-I2S-${COMP}-${INFMT}-${OUTFMT}-48k-24576k-codec.tplg
TPLG=${TPLG_DIR}/${TPLGFN}
[ -f "$TPLG" ] || {
echo
echo "Error: topology $TPLGFN does not exist."
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo

Suggested change
echo "Error: topology $TPLGFN does not exist."
echo "Error: topology $TPLG does not exist."

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed, the previous print was without path. Better this way.

XTRUN_CMD=$XTENSA_PATH/$XTRUN
if $VALGRIND; then
>&2 printf "WARNING: Ignoring VALGRIND with xt-run\n"
VALGRIND=false
Copy link
Collaborator

Choose a reason for hiding this comment

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

indent

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same, I have no idea what's wrong with this indent. My emacs bash mode indents this way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Mix of tabs and spaces again?

tools/test/audio/comp_run.sh Show resolved Hide resolved
test -n "${XTENSA_TOOLS_VERSION}" ||
die "Illegal platform $BUILD_PLATFORM, no XTENSA_TOOLS_VERSION found.\n"
test -n "${XTENSA_CORE}" ||
die "Illegal platform $BUILD_PLATFORM, no XTENSA_CORE found.\n"
Copy link
Collaborator

Choose a reason for hiding this comment

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

indent

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, I have no idea what's wrong with indent. Help?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Spaces on one line and tabs on the next feels fishy, even for shell scripts.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's unfortunate that we have some files with tabs and other files with spaces in the same project but I agree 100% with @paulstelian97 : let's please not cross the line where we have a mix of tabs and spaces in the same file!

So @singalsu please find the shortcut in your editor that lets you quickly switch between tabs and spaces like the rest of us :-)

PS: I can't resist sorry: this sort of time-consuming discussion is exactly why tabs suck. Off-topic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The file is already without my patch a mix of tabs and spaces. I can convert them all to spaces then.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

M-x untabify is now done.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I checked and there are only 5 tabs right now. Feel free to convert them to spaces or to leave them alone, as long as you don't add any it's fine by me.

@singalsu singalsu force-pushed the testbench_surgery branch from d7cd418 to 524f9f9 Compare April 25, 2023 09:31
@singalsu singalsu requested a review from marc-hb April 25, 2023 09:34
@singalsu singalsu force-pushed the testbench_surgery branch from 524f9f9 to 8651092 Compare April 25, 2023 17:30
@singalsu singalsu requested a review from paulstelian97 April 25, 2023 17:30
Copy link
Collaborator

@paulstelian97 paulstelian97 left a comment

Choose a reason for hiding this comment

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

Modulo that one comment this looks good (and I can live with that one too).

void tb_getcycles(uint64_t *cycles)
{
#if defined __XCC__
*cycles = XT_RSR_CCOUNT();
Copy link
Contributor

@btian1 btian1 Apr 26, 2023

Choose a reason for hiding this comment

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

it may be a int32 usage, no need int64.
https://elixir.bootlin.com/zephyr/v1.7.0-rc2/source/drivers/timer/xtensa_sys_timer.c#L41

int32 should be enough, max should be set to: 400,000?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd keep this as 64 bits. With 400 MHz 32 bit counter overflows at 10.7s. Other Xtensas can be over 1 GHz clocked and we can support also other processor simulators too in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

cycle should be a wrap data, once it go to max, then will go back to zero, so there is another issue with the code,
please refer below:

if (cycles1 > cycles0)
	diff = cycles1 - cycles0;
else
	diff = UINT32_MAX - cycles0 + cycles1;

it is not a always increase data.

Copy link
Collaborator

@marc-hb marc-hb Apr 27, 2023

Choose a reason for hiding this comment

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

so there is another issue with the code,

What was the first issue?

cycle should be a wrap data, once it go to max, then will go back to zero,

Yes and that's OK because unsigned integers (unlike signed integers) are guaranteed to wrap around by the C standard

import numpy as np
np.uint32(5) - np.uint32(0xffffffff)

6

https://www.acepace.net/integerQuiz/

@@ -29,14 +31,15 @@ enum file_format {

/* file component state */
struct file_state {
char *fn;
uint64_t cycles_count;
Copy link
Contributor

Choose a reason for hiding this comment

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

int32 should be ok, since it is delta between one module. no way to exceed int32

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it's true a single file copy should not consume over 32 bit worth of cycles but having this 64 bits avoid type casts. The overhead from this is small and it makes this more future proof, so I'd keep it as is. Unless you or others really want me to change this to smaller size.

Copy link
Collaborator

Choose a reason for hiding this comment

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

As far as I understand this code will only ever run on a GHz 64bits CPU so I don't see what difference 32 bits would make.

Mixing signed and unsigned is fraught with peril and signed overflow is undefined so unsigned is clearly better here.

Copy link
Collaborator

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

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

Looks great @singalsu !

singalsu added 4 commits May 4, 2023 15:21
This patch avoids the build errors. Most of the issues are
from different types for formatted printing in gcc vs. xt-xcc.

The "__attribute__ ((fallthrough));" is not supported in xt-xcc.

The xtensa C library does not have clock_gettime() so it is
only left out from build. The cycles count and MCPS is printed
instead.

The include of dlfcn.h is not needed since the testbench no
more has dynamic libraries.

Structs within structs need to be initialized to zero in xt-xcc
with multiple brackets.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This patch adds to rebuild-testbench option -x <platform> that
can be used to build testbench for xt-run execution. The enhanced
script reuses native testbench build but with CC, LD, LDFLAGS,
etc. defines to use the xt-xcc compiler for build.

Currently TGL (HiFi3) is the only supported platform. More will
be added later.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This patch adds to process_test() sixth argument to run the tests
with xt-run environment with argument set to 'xt-run' or
'xt-run --turbo'.

The set and print of LD_LIBRARY_PATH is no more needed with static
testbench version.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
No script changes, just unify shell script style to be
with indents with spaces instead of both tabs and spaces.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
@singalsu singalsu force-pushed the testbench_surgery branch from 8651092 to acdc21f Compare May 4, 2023 12:37
@singalsu
Copy link
Collaborator Author

singalsu commented May 4, 2023

I just rebased this PR and added a commit with only tabs to spaces changes to comp_run.sh.

@kv2019i
Copy link
Collaborator

kv2019i commented May 4, 2023

Style checkpatch warning relates to long string literals -> this is ok

One unrelated fail in https://sof-ci.01.org/sofpr/PR6513/build6991/devicetest/index.html

Proceeding with merge.

@kv2019i kv2019i merged commit 43b08c6 into thesofproject:main May 4, 2023
@singalsu singalsu deleted the testbench_surgery branch May 9, 2023 12:58
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.

8 participants