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

testsuite: Add busy simulator #36662

Merged
merged 2 commits into from
Jul 29, 2021
Merged

Conversation

nordic-krch
Copy link
Contributor

Busy simulator is using counter and entropy devices to randomly trigger counter interrupts and busy loop inside that interrupt for random period of time. Module is using work to produce random values which are stored in the ring buffer. Counter interrupt priority is set in overlay. ZLI will be also an option once #32575 is merged.

Module is indented to be used in testing. Already #36464 was discovered when it was used in the test in a downstream project.

@github-actions github-actions bot added area: Devicetree area: Devicetree Binding PR modifies or adds a Device Tree binding area: Test Framework Issues related not to a particular test, but to the framework instead area: Tests Issues related to a particular existing or missing test labels Jul 1, 2021
@zephyrbot zephyrbot added the area: Testsuite Testsuite label Jul 6, 2021
compatible: "vnd,busy-sim"

properties:
gpios:
Copy link
Member

Choose a reason for hiding this comment

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

What about naming it active-gpios?

Comment on lines 19 to 29
const struct device *entropy;
const struct device *counter;
const struct device *gpio_port;
Copy link
Member

Choose a reason for hiding this comment

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

These fields (and pin as well) can be initialized at compile time, so you could extract those to a separate const structure that could be placed in flash.

Copy link
Contributor

Choose a reason for hiding this comment

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

This should use a gpio_dt_spec, also. Optional properties like active-gpios can be initialized using GPIO_DT_SPEC_GET_OR().

Copy link
Contributor

Choose a reason for hiding this comment

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

This should use a gpio_dt_spec, also. Optional properties like active-gpios can be initialized using GPIO_DT_SPEC_GET_OR().

@nordic-krch did you see this one? Just checking, since you've been pushing other updates.

sim.alarm_cfg.callback = counter_alarm_callback;
sim.alarm_cfg.flags = COUNTER_ALARM_CFG_EXPIRE_WHEN_LATE;

sim.entropy = device_get_binding(DT_CHOSEN_ZEPHYR_ENTROPY_LABEL);
Copy link
Member

Choose a reason for hiding this comment

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

You can initialize this pointer with DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy)).

Comment on lines +9 to +24
void busy_sim_start(uint32_t active_avg, uint32_t active_delta,
uint32_t idle_avg, uint32_t idle_delta);
Copy link
Member

Choose a reason for hiding this comment

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

Some descriptions of these parameters would be helpful.

uint32_t freq;

if (sim.gpio_port) {
gpio_pin_configure(sim.gpio_port, sim.pin,
Copy link
Member

Choose a reason for hiding this comment

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

sim.gpio_port should be checked with device_is_ready() first.


if (sim.gpio_port) {
gpio_pin_configure(sim.gpio_port, sim.pin,
GPIO_OUTPUT | GPIO_OUTPUT_INIT_LOW);
Copy link
Member

Choose a reason for hiding this comment

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

This way the flags specified in DT for this pin are ignored (what may be confusing). It would be better to use GPIO_DT_SPEC_GET() and gpio_pin_configure_dt() for handling the pin. See for instance the button sample:

static struct gpio_dt_spec led = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led0), gpios,
{0});
if (led.port) {
ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT);
.

#include <drivers/counter.h>
#include <drivers/gpio.h>
#include "busy_sim.h"
#include <hal/nrf_gpio.h>
Copy link
Member

Choose a reason for hiding this comment

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

This is not needed.

Comment on lines 155 to 156
It simulates cpu load by using counter device to generate random
interrupts with random busy looping in the interrupt.
Copy link
Member

Choose a reason for hiding this comment

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

The term "random interrupts" is a bit ambiguous. I think something like "interrupts with random intervals" could make it more clear.

@nordic-krch
Copy link
Contributor Author

@anangl thanks for review. I applied all your comments, can you re-review?

Comment on lines 7 to 19
&timer0 {
status = "okay";
interrupts = <8 0>;
busy_sim: vnd-busy-sim {
compatible = "vnd,busy-sim";
active-gpios = <&gpio0 27 GPIO_ACTIVE_HIGH>;
};
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please provide a justification for:

  1. why you're using a parent/child relationship here instead of pointing at the timer instance from the vnd,busy-sim node using a phandle?
  2. why only one device is supported via the busy_sim node label?

If you can support multiple busy simulator devices, I think this should use DT_INST_FOREACH_STATUS_OKAY to initialize them instead, with DT_DRV_COMPAT set to vnd_busy_sim.

If it only makes sense to support one vnd,busy-sim in the system, then why not just use DEVICE_DT_GET_ANY() and add a BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(vnd_busy_sim) == 1)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why you're using a parent/child relationship here instead of pointing at the timer instance from the vnd,busy-sim node using a phandle?

I am not that fluent with device tree options. This one seemed ok to me as busy simulator is built on top of counter instance but i'm not attached to that so if you think it's better to use phandle i can change it. Could you provide justification why it's the way to go?

why only one device is supported via the busy_sim node label?

Since it's for testing purposes only i don't see a need for multiple simulators? Sorry but don't know where should i use DEVICE_DT_GET_ANY(). Can you be more specific?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you provide justification why it's the way to go?

In my experience, parent/child is for controller / peripheral type relationships (compare with SPI, I2C, and flash).

Phandles seem to be used more when you want to say "use peripheral X for this": compare with properties like foo-gpios, dmas, io-channels, etc.

Sorry but don't know where should i use DEVICE_DT_GET_ANY(). Can you be more specific?

Sure; what I mean is that you don't need to force the user to make a node label, even if only one device is supported in the system.

You can do something like this instead (after thinking about it, I think DEVICE_DET_GET_ONE is better than DEVICE_DT_GET_ANY):

BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(vnd_busy_sim) == 1, "add exactly one vnd,busy-sim node to the devicetree");
const struct device *my_busy_sim = DEVICE_DT_GET_ONE(vnd_busy_sim);
if (!device_is_ready(my_busy_sim)) {
        /* ... handle error here ... */
} else {
        /* device is good to go */
}

Then your node doesn't need to be labeled busy_sim in the DTS. You can just make a status okay node with the right compatible and everything just works.

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've converted busy_sim to the device and used phandle for counter. Implemented it as separate commit, will squash if it's ok.

Copy link
Contributor

@mbolivar-nordic mbolivar-nordic left a comment

Choose a reason for hiding this comment

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

Adding a temporary -1 for now until the DT descriptions are sorted out. I think the overall idea makes sense though.

@nordic-krch nordic-krch force-pushed the busy_sim branch 2 times, most recently from d94e95b to 01c50ba Compare July 20, 2021 07:11
@nordic-krch nordic-krch added the DNM This PR should not be merged (Do Not Merge) label Jul 20, 2021
Comment on lines 43 to 40
.gpio_port = DEVICE_DT_GET(DT_GPIO_CTLR(DT_BUSY_SIM, active_gpios)),
.pin = DT_GPIO_PIN(DT_BUSY_SIM, active_gpios),
.pin_spec = GPIO_DT_SPEC_GET_OR(DT_BUSY_SIM, active_gpios, {0}),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is weird. The pin_spec structure already has the port and pin, so this is redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed gpio-port and pin.

@mbolivar-nordic
Copy link
Contributor

Could you please squash things together to make this easier to review?

@nordic-krch
Copy link
Contributor Author

Could you please squash

@mbolivar-nordic done

Copy link
Contributor

@mbolivar-nordic mbolivar-nordic left a comment

Choose a reason for hiding this comment

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

Thanks for squashing. Looking very good to me now, just a couple of minor issues.

subsys/testsuite/busy_sim/busy_sim.c Outdated Show resolved Hide resolved
tests/ztest/busy_sim/boards/nrf52840dk_nrf52840.overlay Outdated Show resolved Hide resolved
tests/ztest/busy_sim/src/main.c Outdated Show resolved Hide resolved
Busy simulator is using counter device and entropy device to
generate random cpu load. Counter device cofiguration can be
used to set cpu load interrupt priority and optional pin that
can be set during the load.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Added test that validates busy simulator.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Copy link
Contributor

@mbolivar-nordic mbolivar-nordic left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM.

@mbolivar-nordic
Copy link
Contributor

nordic-krch added the DNM label 9 days ago

@nordic-krch did you mean to do this, or was it an accident?

@nordic-krch nordic-krch removed the DNM This PR should not be merged (Do Not Merge) label Jul 29, 2021
@nordic-krch
Copy link
Contributor Author

@nordic-krch did you mean to do this, or was it an accident?

Removed, it was added when commits were not squashed.

@nordic-krch
Copy link
Contributor Author

@anangl can you take a look?

@cfriedt cfriedt merged commit 7423f5f into zephyrproject-rtos:main Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree Binding PR modifies or adds a Device Tree binding area: Devicetree area: Test Framework Issues related not to a particular test, but to the framework instead area: Tests Issues related to a particular existing or missing test area: Testsuite Testsuite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants