riscv-collab / riscv-openocd

Fork of OpenOCD that has RISC-V support
Other
453 stars 328 forks source link

Drop the use of `-coreid` in RISC-V targets #1147

Open en-sc opened 1 month ago

en-sc commented 1 month ago

Currently -coreid is used in RISC-V targets as hartid. https://github.com/riscv-collab/riscv-openocd/blob/a4020f1a0207dc218812ee262ce861d81aa7962f/src/target/riscv/riscv-013.c#L1909 This is misleading.

(hartid name is probably not the best. Here it's used just as an example.)

  1. ~By default hartid can be assigned based on target index~ See https://github.com/riscv-collab/riscv-openocd/issues/1147#issuecomment-2416145221
  2. RISC-V-specific -hartid configure option can be introduced.
  3. Configuring -coreid on a RISC-V target should have the same effect as -hartid and a deprecation message should be shown.
JanMatCodasip commented 1 month ago

Hi @en-sc

I agree that the name -coreid is misleading in case of RISC-V.

By default hartid can be assigned based on target index.

I am not sure I understand this fully. Where would the hard index be taken from if -coreid is removed?

RISC-V-specific -hartid configure option can be introduced.

That'd be my preference. Furthermore:

en-sc commented 1 month ago

It'd be good to still support -coreid but show a deprecation warning

You are right. Updated the description.

I am not sure I understand this fully. Where would the hard index be taken from if -coreid is removed?

From the order the targets are created in:

target create ... # hartid implicitly 0
target create ... # hartid implicitly 1

IMHO it's a nice default, considering that the targets are usually the same anyway (SMP) (especially when they are connected to the same DM).

Moreover, this will make validation of hartid unnecessary (it should be contiguous and start from zero).

And there is also the case of a platform with multiple DMs (here hartid is not unique).

JanMatCodasip commented 1 month ago

Where would the hard index be taken from if -coreid is removed?

From the order the targets are created in

I'd strongly prefer to not have implicitly incrementing hart numbers for these reasons:

Furthermore, it'd be good to check the uniqueness of hart number for a given debug module (that is, for a given pair of JTAG TAP and -dbgbase).

en-sc commented 1 month ago

I see your point, however I'd like to disagree:

To not change the behavior: now omitted hart ID means fixed 0, after the change the omitted hart ID would behave very differently

This is not true. AFAIU, if harts with omitted hart ID are on the same DM -- it's an error that is not currently diagnosed. If hart ID is specified with a value greater then the detected number of harts on the DM --it's also an error that is not diagnosed. (it sometimes "works" since hartsel is WARL). What I'm trying to say is, IMHO there is not much "behavior" to preserve here.

For various (less or more obscure) reasons the user may not want to debug all harts belonging to a given debug module. For example the user may only be interested in debugging harts 0 and 3.

AFAIU, this is a non-default scenario which can be covered by non-default config.

For clarity ("explicit is better than implicit" - PEP 20)

Oh why did you have to quote PEP here.. I'd agree with the argument but I hate Python with all my heart :)

en-sc commented 1 month ago

In all seriousness though, my main argument is: assigning hartid based on target index makes it correct by default most of the time. Otherwise extensive verification is required.

E.g.a system with two DMs on one TAP:

You can see that requiring the user to specify hartid explicitly makes it so the user needs to specify information that can be easily examined (and should be examined to verify that user configuration is correct).

JanMatCodasip commented 1 month ago

me: To not change the behavior: now omitted hart ID means fixed 0, after the change the omitted hart ID would behave very differently

en-sc: This is not true. AFAIU, if harts with omitted hart ID are on the same DM -- it's an error that is not currently diagnosed. (...) IMHO there is not much "behavior" to preserve here.

Fair point, I agree!

I also am in agreement that OpenOCD should auto-detect the base addresses of all DMs and the number of harts on each DM.

me: For various (less or more obscure) reasons the user may not want to debug all harts (...).

en-sc: AFAIU, this is a non-default scenario which can be covered by non-default config.

I would like there to not be two ways of writing the configuration (default vs. non-default, or we could call them automatic vs. explicit).

In my opinion, the only advantage of the "automatic" configuration is shorter configuration - less characters to type.

Other than that, I am afraid that I can only see disadvantages:

For those reasons, I'd prefer to not have the automatic configuration.

To summarize, my preference would be: