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

target/riscv: Add support for external triggers #1179

Open
wants to merge 1 commit into
base: riscv
Choose a base branch
from

Conversation

rbradford
Copy link

Add support for associating a halt group with an external trigger via a newly exposed configuration option "riscv set_external_trigger".

Change-Id: If10c67d2e14d8bc7cd6d59011b3215fda4ff4b02

@aap-sc aap-sc requested a review from en-sc December 2, 2024 17:12
doc/openocd.texi Outdated
@@ -11476,6 +11476,11 @@ The second argument configures how OpenOCD should use the selected trigger featu
With no parameters, prints current trigger features configuration.
@end deffn

@deffn {Command} {riscv set_external_trigger} value
Associate the supplied external trigger with the SMP halt group for the harts. When the external trigger
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe that external trigger does not necessarily implies and SMP group.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you - i've dropped the word "SMP" from the documentation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we decide to keep the status quo -- keep using halt groups for SMP groups -- then a simple Tcl command like this looks all right to me.

Few suggestions:

  • One halt group can have multiple external triggers (1:N relationship). So I'd call the command add rather than set.
  • Since the command is only used in the configuration phase (COMMAND_CONFIG), it looks unnecessary to have a remove command to remove the trigger from the group.
  • If the current relationship between halt groups and SMP stays in place, then the command name can contain smp -- as an additional hint for the user that it will apply to the whole SMP group.
  • The command should contain halt or halt_group somewhere it its name to indicate it is for halt groups, not for resume groups.

For example:

[target_name] riscv smp_add_ext_trigger halt_group <ext_trigger_number>
# halt_group would remain the only supported trigger type for the time being

Add support for associating a halt group with an external trigger via a
newly exposed configuration option "riscv set_external_trigger".

Change-Id: If10c67d2e14d8bc7cd6d59011b3215fda4ff4b02
Signed-off-by: Rob Bradford <[email protected]>
@aap-sc
Copy link
Collaborator

aap-sc commented Dec 2, 2024

@rbradford I've left some additional comments. Though, I believe we are far from done :(.

The more I look at this patch and the the current codebase - the more concerns I have.

Please, keep in mind that the current implementation of halt groups in OpenOCD is very questionable leading to issues like #902 .

I would go as far as to say that the concept of halt groups is not implemented properly. The more I look at the relevant codebase - the more it seems to me that proper support for halt/resume groups should be implemented first. Once that is done we could adopt something like this patch. Others could have a different opinion, though - @JanMatCodasip , @en-sc do you have any comments regarding the matter?

@@ -2051,6 +2077,9 @@ static int examine(struct target *target)
else
LOG_TARGET_INFO(target, "Core %d could not be made part of halt group %d.",
info->index, target->smp);
if (r->external_trigger)
Copy link
Collaborator

@aap-sc aap-sc Dec 2, 2024

Choose a reason for hiding this comment

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

  1. it's not quite clear why this code is under target->smp condition. We can control an external triggger without creating an SMP group.
  2. @en-sc I remember you wanted to implement an interface to debug module. Could you please assess if we can implement the functionality in question without this interface?
  3. if (r->external_trigger) condition is dubious, since even the debug spec implies that external trigger
    have numbers starting from "0":
By convention external triggers 0-7 are bidirectional,
triggers 8-11 are input-only, and triggers 12-15 are output-only but this is not required.
  1. what about trigger directions?
  2. do you have plans to add tests targeting this functionality?

Copy link
Author

Choose a reason for hiding this comment

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

@aap-sc Thanks for taking the time to reply - some specific answers to your points

  1. I was using target->smp as that was a condition to have access to a halt group
  2. Well spotted - indeed trigger 0 is valid - this is wrong (I used external trigger 1 in my Spike test version for this change which is why I didn't spot this.) I will address this
  3. I'm not sure trigger direction is something OpenOCD can handle since it's just a convention in the numbering
  4. I hacked Spike to group some harts together separately and then "joined" them with an external trigger.

@@ -11476,6 +11476,11 @@ The second argument configures how OpenOCD should use the selected trigger featu
With no parameters, prints current trigger features configuration.
@end deffn

@deffn {Command} {riscv set_external_trigger} value
Copy link
Collaborator

Choose a reason for hiding this comment

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

RISC-V debug spec allows external triggers to be associated with halt and resume groups. I assume you are trying to add support for halt groups only. Looks like this command needs to be renamed, since resume groups are out of scope, or you should extend the interface to support resume groups too.

Copy link
Author

Choose a reason for hiding this comment

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

Indeed - my initial focus was only halt groups - this should be renamed if we go ahead with this very limited solution.

@JanMatCodasip
Copy link
Collaborator

I will be able to take a closer look at the end of this week.

@@ -11476,6 +11476,11 @@ The second argument configures how OpenOCD should use the selected trigger featu
With no parameters, prints current trigger features configuration.
@end deffn

@deffn {Command} {riscv set_external_trigger} value
Copy link
Contributor

Choose a reason for hiding this comment

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

My initial idea was to create external triggers separately in the cfg file and list them in the target smp command, something like this:

# when no dmexttrigger
target create hart0 riscv -dbgbase 0
target create hart1 riscv -dbgbase 0x400
target smp hart0 hart1

# when support dmexttrigger, type0 halt, type1 resume
target create dm0extrigger0 riscv-dmexttrigger -index 0 -type 0  -dbgbase 0
target create dm0extrigger1 riscv-dmexttrigger  -index 1 -type 0  -dbgbase 0
target create hart0 riscv -dbgbase 0
target create dm1extrigger0 riscv-dmexttrigger -index 0 -type 0  -dbgbase 0x400
target create dm1extrigger1 riscv-dmexttrigger -index 1 -type 0  -dbgbase 0x400
target create hart1 riscv -dbgbase 0x400
target smp hart0 hart1 dm0extrigger0  dm0extrigger1  dm1extrigger0 dm1extrigger1

But there are a lot of changes required, so currently associating external trigger with a target seems like an easy enough way to start supporting it.

Suppose we support it this way, then my suggestion is let this cmd support multiple external triggers instead of just one.
For example, if the external trigger is not bidirectional, we need at least two triggers, one input-only and one output-only, to support smp with cores on other DM.
There are more complex situations that may require more triggers.

Copy link
Author

Choose a reason for hiding this comment

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

The design of this syntax looks really nice - i'm very happy to wait on this or if you prefer take a go at implementing that style myself?

Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't started looking at the code yet, just a basic idea that needs further thought.
I think we can move forward with your current implementation and make the external trigger available to those who need it first.

Copy link
Collaborator

@JanMatCodasip JanMatCodasip Dec 17, 2024

Choose a reason for hiding this comment

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

@zqb-all Thank you for your idea above.

Still, I'd recommend to not abuse target create in order to assign external triggers to SMP groups. "Target" has a well-defined meaning in OpenOCD: it is a debuggable entity with its state, registers, target API operations (target_type.h), ... External trigger is not a target. So I'd prefer to find a different syntax to assign external triggers to halt goups.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still, I'd recommend to not abuse target create in order to assign external triggers to SMP groups.

Agreed. Some concepts in debug spec are not explicitly represented in OpenOCD cfg file now. For example, DM is only specified with dbgbase when target create, and halt group is only implicitly used for target smp, so it is not easy to create a suitable syntax to configure a dmextrigger to a specific group now.
When I have a more mature idea, I will create another PR to discuss it.
Thank you for your feedback on this idea.

return ERROR_FAIL;
}

r->external_trigger = value;
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be safer to add some checks to prevent user from associating one trigger to multiple harts on same DM.

Copy link
Author

Choose a reason for hiding this comment

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

Indeed this is a good point - the external trigger is logically associated with a halt group which will span multiple targets (assuming the one target per hart configuration method.)

@JanMatCodasip
Copy link
Collaborator

aap-sc: The more I look at this patch and the the current codebase - the more concerns I have. [...]
JanMatCodasip, en-sc do you have any comments regarding the matter?

I will take a close look at the SMP / halt-resume groups implementation to form an opinion on this matter (which I wanted to do anyway). It just may take me a day or two to get to this.

@JanMatCodasip
Copy link
Collaborator

JanMatCodasip commented Dec 17, 2024

Hello all, I have checked the overall state of SMP and halt/resume groups in riscv-openocd.

To summarize the current state:

  • Riscv-openocd currently implements halt groups only. Resume groups are not implemented.
  • Halt groups are used only in relationship with the SMP mode.
  • External triggers for halt/resume groups are not implemented.

Comments, questions:

  1. Halt groups are implemented only in relationship with SMP. Do we wish to keep that approach or allow placing also singular (non-SMP) targets into halt groups?

  2. As an alternative, the user could create SMP group with just a single target (hart).

  3. Riscv-openocd auto-selects the halt group number for each SMP group (sequentially: 1, 2, 3, ...). Do we wish to keep it that way or give the user control over the halt group numbers?

  4. External triggers for halt groups seem OK to be implemented. We just need to agree on the solution, which is already happening in this PR :)

  5. Resume groups alone (without external triggers) do not seem to bring any benefit. Near-simultaneous resume of multiple harts is already implemented by selecting the harts and then resuming.

  6. Resume groups with external output triggers could be eventually implemented into riscv-openocd, if desired. I don't see any principal problem there.

  7. Resume groups with external input triggers look to be very problematic. Neither OpenOCD nor GDB is ready for the case when a target suddenly resumes (due to the trigger), without an explicit resume request and at arbitrary moment in time.

Comment on lines +194 to +195
/* Halt group may be associated with an external trigger */
unsigned int external_trigger;
Copy link
Collaborator

Choose a reason for hiding this comment

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

As pointed out in another comment, there can be multiple external triggers in a halt (or resume) group.

The code, on the other hand, seems to force 1:1 relationship.

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.

4 participants