-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
drivers: cache: add Andes cache driver #67898
drivers: cache: add Andes cache driver #67898
Conversation
a4e606b
to
ddd2ad1
Compare
soc/riscv/andes_v5/ae350/Kconfig.soc
Outdated
# Workaround for not being able to have commas in macro arguments | ||
DT_ANDESTECH_L2C := andestech,l2c | ||
|
||
config SOC_ANDES_V5_L2C | ||
bool | ||
default $(dt_compat_enabled,$(DT_ANDESTECH_L2C)) | ||
|
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.
It might make more sense to mark this as deprecated instead of immediately removing it, even if it does nothing.
So remove the default line, add select DEPRECATED
.
That should allow for downstream users to use the same Kconfig between adjacent Zephyr releases, and they should get a warning in CI about using deprecated options.
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.
+1 on marking this as deprecated
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! I'll add select DEPRECATED
.
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 doesn't look very 'driver', but should be possible to make it so by adding a binding file for andestech,l2c
& use proper devicetree macros for driver and DT_INST_FOREACH_STATUS_OKAY
instead of SYS_INIT
drivers/cache/cache_andes.c
Outdated
|
||
#define L2C_EXISTS DT_NODE_HAS_COMPAT_STATUS(DT_NODE_EXISTS( \ | ||
DT_NODELABEL(l2_cache)), andestech_l2c, okay) | ||
#ifdef L2C_EXISTS |
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 will resolve to true
regardless of the result in L29, should probably be
#ifdef L2C_EXISTS | |
#if IS_ENABLED(L2C_EXISTS) |
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 catching it up! DT_NODE_HAS_COMPAT_STATUS
would return 0 or 1, so I think #if L2C_EXISTS
would be enough?
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.
#if L2C_EXISTS
would be enough?
yeah that will do as well
drivers/cache/cache_andes.c
Outdated
#define L2C_EXISTS DT_NODE_HAS_COMPAT_STATUS(DT_NODE_EXISTS( \ | ||
DT_NODELABEL(l2_cache)), andestech_l2c, okay) |
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 means the node must be named as l2_cache
in the devicetree
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 the suggestions!
-
I'll add the binding file, and check L2 cache DTS node by compatible
-
I'm not sure about the issues in
DT_INST_FOREACH_STATUS_OKAY
andSYS_INIT
.
There are two macros:SYS_INIT
andDEVICE_DT_INST_DEFINE
for setting drivers up for boot time initialization.
DEVICE_DT_INST_DEFINE
which will create a driver object isn't needed for the cache driver.DT_INST_FOREACH_STATUS_OKAY
is used in the case that there are multiple nodes. However, in the current
implementation of the Andes cache driver, the focus is solely on a single L2 cache node.
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.
2.
DT_INST_FOREACH_STATUS_OKAY
is used in the case that there are multiple nodes.
Sorry that was a typo - should be DEVICE_DT_INST_DEFINE
/ DEVICE_DT_DEFINE
instead
However, in the current implementation of the Andes cache driver, the focus is solely on a single L2 cache node.
Yeah they both work as fine for a single instance device driver like this without a device API, it's just that the DT_
variant is designed for device drivers and opens to more possibilities in the future. It's nice to refactor this driver a bit at the very beginning to make use of the device driver macros and make these
static struct cache_config cache_cfg; /* this can go to the 'config' of the device */
static struct k_spinlock lock; /* this can go to the 'data' of the device */
instance based so that the driver can be made multi-instance very easily in the future.
But these are all just suggestions.
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.
We have explored the concept of a multi-instance-based driver, but its viability is challenged when confronted with the introduction of a multi-level cache system. Simply parsing the L2 cache node is insufficient to address this complexity.
In a multi-level cache setup, there could be a scenario where each core has its private L2 cache, or two cores share an L2 cache, or with an additional L3 cache. This introduces a set of challenges: determining which level to treat as instances and, when performing cache operations, identifying the appropriate next-level cache. If we limit our focus to parsing the L2 cache exclusively, we not only overlook scenarios involving multiple L2 cache nodes but also make the code less adaptable for future refactoring.
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.
it would probably be much easier to read if the l2 cache related logics are factorized into functions and moved into a separate file of its own, then make use of CMakeLists.txt
to compile it if enabled in the devicetree, rather than having 9 chunks of L2C_EXISTS
macro guards scattered throughout this cache driver which involved syscon
(+ andestech,atcsmu100
), l1_cache
& l2_cache
I'm not experienced in the workings of cache, so take these comments with a pinch of salt:
Some of the concerns above sound like a devicetree problem to me, is it possible to allocate these little pools of memory in the devicetree, perhaps with another device binding if necessary?
I'm actually suggesting that things can be split-off from the
The current With that I think perhaps it makes sense to have multiple files (drivers?) that serve as backends and register itself with the main |
Yes, these concerns can be solved by adding some device properties, just like 'next-level-cache' mentioned in devicetree-specification-v0.4. But in our plan, we'll add these features when there is a real hardware requirement.
Agree with the concept of making the source code of each cache level more adaptable.
If it is legal to have multiple files(drivers), we've already had another solution. In this way, we think we can append another cache level more easily in the future.
|
ddd2ad1
to
72105b5
Compare
The twister-build error is a Kconfig loop dependency. It happened when I added a Kconfig dependency between Is there anyone who can address the issue, or should I file an issue to seek help? |
looks like the build system 'saw' the zephyr/soc/riscv/neorv32/Kconfig.defconfig Lines 18 to 20 in 1970004
before the real one in the SYSCON driver: Lines 9 to 18 in 1970004
no idea why it does that though, cc @carlocaione |
Can you move the setting of |
Hi @carlocaione, there are still errors even when I move the settings of |
Yeah, no idea. This needs to be debugged. |
72105b5
to
aedb780
Compare
aedb780
to
2d7e254
Compare
2d7e254
to
8772095
Compare
The Kconfig dependency errors happen when the dependency between |
imply DCACHE_LINE_SIZE_DETECT | ||
imply ICACHE_LINE_SIZE_DETECT |
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.
Shouldn't we have here also a dependency on DT_HAS_...
?
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.
In the andes cache driver, syscon driver is only needed when the L2 cache exists.
For DCACHE_LINE_SIZE_DETECT
, there are already dependencies:
DCACHE_LINE_SIZE_DETECT
--> DCACHE
--> CPU_HAS_DCACHE
(depends on -->)
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.
@wtlee1995 - the dependencies are good. Actually both are fine. What Carlo is describing is a relatively new (>3.x.x) facility that reduces the number of "switches" required to enable a driver.
Prior to DT_HAS_FOO
(an "automatic" Kconfig), one needed to set status = "okay"
and also set CONFIG_FOO=y
. Now it's only necessary to enable the node in devictree (approximately). So 1 "switch" instead of 2.
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 understand the benefit of using DT_HAS_...
which can reduce the number of "switches" to enable the driver.
There is no specified cache DTS node, but rather the Kconfig option CPU_HAS_DCACHE
. And we think there is already a hidden dependency between CACHE_ANDES
and CPU_HAS_DCACHE
, so we don't need to add another dependency in the driver.
As for SYSCON
and DCACHE_LINE_SIZE_DETECT
, they are not mandatory options to enable the driver; they are merely enhanced features. Additionally, the Andes cache driver targets for the platform with either (a) only L1 cache or (b) both L1 and L2 cache. Regardless of whether it's (a) or (b), we want to enable DCACHE_LINE_SIZE_DETECT
by default. And we want to enable SYSON
only in (b).
8772095
to
2361324
Compare
Add some definitions for cache driver. Signed-off-by: Wei-Tai Lee <wtlee@andestech.com>
Add cache driver for Andes cache. Signed-off-by: Wei-Tai Lee <wtlee@andestech.com>
Configure default cache driver as external cache driver. Signed-off-by: Wei-Tai Lee <wtlee@andestech.com>
Replace l2_cache.c with cache driver. Signed-off-by: Wei-Tai Lee <wtlee@andestech.com>
To descibe the AndesTech L2 cache. Besides, remove redundant property in dtsi. Signed-off-by: Wei-Tai Lee <wtlee@andestech.com>
Since Andes cache implementation is supported, remove adp_xc7k/ae350 from the blacklist. Signed-off-by: Wei-Tai Lee <wtlee@andestech.com>
2361324
to
473e692
Compare
Change |
Added cache driver for Andes V5 series SOC and tested on adp_xc7k_ae350 board.
Signed-off-by: Wei-Tai Lee wtlee@andestech.com