-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Conversation
dts/bindings/test/vnd,busy-sim.yaml
Outdated
compatible: "vnd,busy-sim" | ||
|
||
properties: | ||
gpios: |
There was a problem hiding this comment.
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
?
subsys/testsuite/busy_sim/busy_sim.c
Outdated
const struct device *entropy; | ||
const struct device *counter; | ||
const struct device *gpio_port; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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().
There was a problem hiding this comment.
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.
subsys/testsuite/busy_sim/busy_sim.c
Outdated
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); |
There was a problem hiding this comment.
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))
.
void busy_sim_start(uint32_t active_avg, uint32_t active_delta, | ||
uint32_t idle_avg, uint32_t idle_delta); |
There was a problem hiding this comment.
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.
subsys/testsuite/busy_sim/busy_sim.c
Outdated
uint32_t freq; | ||
|
||
if (sim.gpio_port) { | ||
gpio_pin_configure(sim.gpio_port, sim.pin, |
There was a problem hiding this comment.
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.
subsys/testsuite/busy_sim/busy_sim.c
Outdated
|
||
if (sim.gpio_port) { | ||
gpio_pin_configure(sim.gpio_port, sim.pin, | ||
GPIO_OUTPUT | GPIO_OUTPUT_INIT_LOW); |
There was a problem hiding this comment.
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:
zephyr/samples/basic/button/src/main.c
Lines 32 to 33 in bf3c6e7
static struct gpio_dt_spec led = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led0), gpios, | |
{0}); |
zephyr/samples/basic/button/src/main.c
Lines 75 to 76 in bf3c6e7
if (led.port) { | |
ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT); |
subsys/testsuite/busy_sim/busy_sim.c
Outdated
#include <drivers/counter.h> | ||
#include <drivers/gpio.h> | ||
#include "busy_sim.h" | ||
#include <hal/nrf_gpio.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed.
subsys/testsuite/Kconfig
Outdated
It simulates cpu load by using counter device to generate random | ||
interrupts with random busy looping in the interrupt. |
There was a problem hiding this comment.
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.
@anangl thanks for review. I applied all your comments, can you re-review? |
&timer0 { | ||
status = "okay"; | ||
interrupts = <8 0>; | ||
busy_sim: vnd-busy-sim { | ||
compatible = "vnd,busy-sim"; | ||
active-gpios = <&gpio0 27 GPIO_ACTIVE_HIGH>; | ||
}; | ||
}; |
There was a problem hiding this comment.
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:
- 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?
- 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)
?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
d94e95b
to
01c50ba
Compare
subsys/testsuite/busy_sim/busy_sim.c
Outdated
.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}), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
Could you please squash things together to make this easier to review? |
@mbolivar-nordic done |
There was a problem hiding this 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.
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM.
@nordic-krch did you mean to do this, or was it an accident? |
Removed, it was added when commits were not squashed. |
@anangl can you take a look? |
Busy simulator is using
counter
andentropy
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.