Skip to contentSkip to conversation

MIPS: Add cacheinfo support

RFC In review [email protected] 5 participants 15 messages Dec 8, 2016 – Dec 13, 2016 MIPS

lore
Share & tools
lore
#0 lore raw

RFC 1/1 MIPS: Add cacheinfo support

From: Justin Chen <[email protected]>

Add cacheinfo support for MIPS architectures.

Use information from the cpuinfo_mips struct to populate the cacheinfo struct. This allows an architecture agnostic approach, however this also means if cache information is not properly populated within the cpuinfo_mips struct, there is nothing we can do. (I.E. c-r3k.c)

---
 arch/mips/kernel/Makefile    |  2 +-
 arch/mips/kernel/cacheinfo.c | 85 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/kernel/cacheinfo.c
arch/mips/kernel/Makefile +1 -1
index 4a603a3..904a9c4 100644
@@ -7,7 +7,7 @@ extra-y		:= head.o vmlinux.lds
 obj-y		+= cpu-probe.o branch.o elf.o entry.o genex.o idle.o irq.o \
 		   process.o prom.o ptrace.o reset.o setup.o signal.o \
 		   syscall.o time.o topology.o traps.o unaligned.o watch.o \
-		   vdso.o
+		   vdso.o cacheinfo.o
 
 ifdef CONFIG_FUNCTION_TRACER
 CFLAGS_REMOVE_ftrace.o = -pg
arch/mips/kernel/cacheinfo.c new file +85 -0

85 lines not on this page · raw message

Signature · 1 line
2.10.2
#1 lore raw
Quoted 11 lines · Justin Chen

From: Justin Chen <[email protected]>

Add cacheinfo support for MIPS architectures.

Use information from the cpuinfo_mips struct to populate the cacheinfo struct. This allows an architecture agnostic approach, however this also means if cache information is not properly populated within the cpuinfo_mips struct, there is nothing we can do. (I.E. c-r3k.c)

Justin, for architecture agnostic approach of work with caches the cpuinfo_mips lacks more information:

1.  L1I-L1D coherency status (is L1I coherent to L1D)
2.  L1D-L2 coherency status (is L1D coherent to L2)
3.  L1I-L2 coherency status (is L1I coherent to L2)
4.  L1I refill from L1D (snoops L1D) or L2 (may require L1D flush)?
5.  L1D cache aliasing disabled by HW
6.  L1I cache aliasing disabled by HW
7.  Barrier existence and it's type between various cache flushes as is as between cache flush and final (completed) state.
8.  Cache ownership (current: assumed that sibling CPUs share L1 - may be shared_cpu_map?)
9.  Is address cache flush operation global in system or pure local?

10. Is index cache flush operation global in system or pure local?

Without that the proposed cpuinfo_mips struct is basically useless.

Regards,
- Leonid

#2 lore raw
Quoted 30 lines · Leonid Yegoshin
Quoted 12 lines · Justin Chen

From: Justin Chen <[email protected]>

Add cacheinfo support for MIPS architectures.

Use information from the cpuinfo_mips struct to populate the cacheinfo struct. This allows an architecture agnostic approach, however this also means if cache information is not properly populated within the cpuinfo_mips struct, there is nothing we can do. (I.E. c-r3k.c)

Justin, for architecture agnostic approach of work with caches the cpuinfo_mips lacks more information:

1.  L1I-L1D coherency status (is L1I coherent to L1D)
2.  L1D-L2 coherency status (is L1D coherent to L2)
3.  L1I-L2 coherency status (is L1I coherent to L2)
4.  L1I refill from L1D (snoops L1D) or L2 (may require L1D flush)?
5.  L1D cache aliasing disabled by HW
6.  L1I cache aliasing disabled by HW
7.  Barrier existence and it's type between various cache flushes as is as

between cache flush and final (completed) state.
8. Cache ownership (current: assumed that sibling CPUs share L1 - may be shared_cpu_map?)
9. Is address cache flush operation global in system or pure local?
10. Is index cache flush operation global in system or pure local?

Quoted 4 lines

Without that the proposed cpuinfo_mips struct is basically useless.

Regards,
- Leonid

Thanks for the comments Leonid.

We should consider the scope of this patch. The information we are trying to expose to userspace is limited to the struct cacheinfo located at include/linux/cacheinfo.c (of course this can always be expanded). So the question is what information would be useful to expose to userspace.
Some justification for exposing the current information in the cacheinfo struct could be: (Pulled from another email chain) "Agreed. So far I have got requests from GCC, JIT and graphics guys. IIUC they need this to support cache flushing for user applications like gcc trampolines and JIT compilers. I am also told that having knowledge of cache architecture can help optimal code strategies, though I don't have much details on that."
https://patchwork.kernel.org/patch/5867721/

There may be justification for including the points you mentioned above, but I believe that is outside the scope of this patch. The cache information exposed in this patch is limited, but I do not believe it is useless. The points above can be added, but it will require a rework of the base cacheinfo driver. driver/base/cacheinfo.c

Thanks,
Justin

#3 lore raw
Quoted 16 lines · Justin Chen

Thanks for the comments Leonid.

We should consider the scope of this patch. The information we are trying to expose to userspace is limited to the struct cacheinfo located at include/linux/cacheinfo.c (of course this can always be expanded). So the question is what information would be useful to expose to userspace.
Some justification for exposing the current information in the cacheinfo struct could be: (Pulled from another email chain) "Agreed. So far I have got requests from GCC, JIT and graphics guys. IIUC they need this to support cache flushing for user applications like gcc trampolines and JIT compilers. I am also told that having knowledge of cache architecture can help optimal code strategies, though I don't have much details on that."
https://patchwork.kernel.org/patch/5867721/

Quoted 7 lines

There may be justification for including the points you mentioned above, but I believe that is outside the scope of this patch. The cache information exposed in this patch is limited, but I do not believe it is useless. The points above can be added, but it will require a rework of the base cacheinfo driver. driver/base/cacheinfo.c

Justin,

CACHE instruction is not available in user space, only SYNCI on MIPS R2+ for trampoline. Any operation with CACHE requires a syscall.

As for SYNCI (trampoline from L1D->L1I) the following information in user space is needed:

1. L1 line size (available via RDHWR $x, $1). It is available now
directly from CPU, but may be better to supply from kernel because some cores has no that.

2. The flag that L1I is NOT coherent with L1D and SYNCI is needed
and available

The knowledge about L1/L2 sizes is not needed for regular application... well, if application wants to get advantage of cache sizes, well, in this case it can be supplied.

But it is unreliable because app may be rescheduled into different kind of core which has a different L1 size (in heterogeneous system, BTW). It can be fixed by setting affinity, of course (not sure - can it be reliably done in BIG/LITTLE approach). But that requires in application the knowledge and understanding of system CPU structure... well why we can allow all that stuff besides information purpose? It corrupts the all efforts and optimization in kernel about performance and powersaving.

Regards,
- Leonid.

#4 lore raw
Quoted 33 lines · Leonid Yegoshin
Quoted 16 lines · Justin Chen

Thanks for the comments Leonid.

We should consider the scope of this patch. The information we are trying to expose to userspace is limited to the struct cacheinfo located at include/linux/cacheinfo.c (of course this can always be expanded). So the question is what information would be useful to expose to userspace.
Some justification for exposing the current information in the cacheinfo struct could be: (Pulled from another email chain) "Agreed. So far I have got requests from GCC, JIT and graphics guys. IIUC they need this to support cache flushing for user applications like gcc trampolines and JIT compilers. I am also told that having knowledge of cache architecture can help optimal code strategies, though I don't have much details on that."
https://patchwork.kernel.org/patch/5867721/

Quoted 7 lines

There may be justification for including the points you mentioned above, but I believe that is outside the scope of this patch. The cache information exposed in this patch is limited, but I do not believe it is useless. The points above can be added, but it will require a rework of the base cacheinfo driver. driver/base/cacheinfo.c

Justin,

CACHE instruction is not available in user space, only SYNCI on MIPS R2+ for trampoline.
Any operation with CACHE requires a syscall.

As for SYNCI (trampoline from L1D->L1I) the following information in user space is needed:

Quoted 6 lines

1. L1 line size (available via RDHWR $x, $1). It is available now
directly from CPU, but may be better to supply from kernel because some cores has no that.

2. The flag that L1I is NOT coherent with L1D and SYNCI is needed
and available

Available but not exposed AFAICT.

Quoted 5 lines

The knowledge about L1/L2 sizes is not needed for regular application... well, if application wants to get advantage of cache sizes, well, in this case it can be supplied.

Quoted 7 lines

But it is unreliable because app may be rescheduled into different kind of core which has a different L1 size (in heterogeneous system, BTW). It can be fixed by setting affinity, of course (not sure - can it be reliably done in BIG/LITTLE approach). But that requires in application the knowledge and understanding of system CPU structure... well why we can allow all that stuff besides information purpose? It corrupts the all efforts and optimization in kernel about performance and powersaving.

What Justin's patch is about is not so much about providing hints to user-space to bypass the kernel's own management of caches, (even though that has been used as an argument by the original introduction of cacheinfo), but more to provide some information to user-space about the cache topology and hierarchy.

Even though this is limited information this is still helpful to applications like lshw and others out there.

What would be needed from your perspective to get cacheinfo added to MIPS, shall we go back and address your initial comment about all the little details about coherency, snooping and re-filling strategy?

Thanks

Signature · 1 line
Florian
#5 lore raw
Quoted 6 lines · Florian Fainelli

What Justin's patch is about is not so much about providing hints to user-space to bypass the kernel's own management of caches, (even though that has been used as an argument by the original introduction of cacheinfo), but more to provide some information to user-space about the cache topology and hierarchy.

I missed that, if it is for information purpose only, then it is OK.

Quoted 7 lines

Even though this is limited information this is still helpful to applications like lshw and others out there.

What would be needed from your perspective to get cacheinfo added to MIPS, shall we go back and address your initial comment about all the little details about coherency, snooping and re-filling strategy?

It depends. Initially, I thought Justin wants to replace arch/mips/mm/c-XXX.c with some universal approach and listed the missed stuff for that (I actually missed some more points in that list).

But for information purpose I don't have any more addition to Justin's patch... may be the coherency status, it has impact on performance: coherency of L1D->L2, L2->memory and L1I->L1D/L2.

- Leonid

#6 lore raw
Quoted 18 lines · Leonid Yegoshin
Quoted 6 lines · Florian Fainelli

What Justin's patch is about is not so much about providing hints to user-space to bypass the kernel's own management of caches, (even though that has been used as an argument by the original introduction of cacheinfo), but more to provide some information to user-space about the cache topology and hierarchy.

I missed that, if it is for information purpose only, then it is OK.

Quoted 7 lines

Even though this is limited information this is still helpful to applications like lshw and others out there.

What would be needed from your perspective to get cacheinfo added to MIPS, shall we go back and address your initial comment about all the little details about coherency, snooping and re-filling strategy?

Quoted 7 lines

It depends. Initially, I thought Justin wants to replace arch/mips/mm/c-XXX.c with some universal approach and listed the missed stuff for that (I actually missed some more points in that list).

But for information purpose I don't have any more addition to Justin's patch... may be the coherency status, it has impact on performance:
coherency of L1D->L2, L2->memory and L1I->L1D/L2.

OK, how would you want that to be represented? Should we try to "link" with the leaf we are coherent with? For instance, if the L1D cache is coherent with the L2, we have something like this:

# Assuming this is L1D cache:
/sys/devices/system/cpu/cpu0/cache/index0
ls -1
coherency_line_size
level
number_of_sets
physical_line_partition
power/
shared_cpu_list
shared_cpu_map
size
type
uevent
ways_of_associativity

We add a new symbolic link, e.g:

coherent_with -> ../index1

that indicates that this cache is coherent with the cache pointed at by directory index1.

Thanks!

Signature · 1 line
Florian
#7 lore raw
Quoted 19 lines · Florian Fainelli

OK, how would you want that to be represented? Should we try to "link" with the leaf we are coherent with? For instance, if the L1D cache is coherent with the L2, we have something like this:

# Assuming this is L1D cache:
/sys/devices/system/cpu/cpu0/cache/index0
ls -1
coherency_line_size
level
number_of_sets
physical_line_partition
power/
shared_cpu_list
shared_cpu_map
size
type
uevent
ways_of_associativity

Quoted 8 lines

We add a new symbolic link, e.g:

coherent_with -> ../index1

that indicates that this cache is coherent with the cache pointed at by directory index1.

Thanks!

Well, I prefer the collection of 3 flags:

flush_required        - or flush to next level is required to force coherency between this level and next after update of this level
invalidate_required   - or invalidate is required to force coherency between this level and next after update of next level
coherent_to_level     - object is coherent with this level (only one domain of coherency on this level is assumed)

So, the standard MIPS L1D could be "flush_required", "invalidate_required" and "coherent_to_level", L1I could be "invalidate_required" and a fully coherent MIPS I6400 L1D could be just "coherent_to_level" (no flush/invalidate required).

The reason why I don't like symlink here because it is more precise information and it immediately pulls the question "do we need to have horizontal links like CPU0 L1D is coherent with CPU1 L1D?" or "do we need to have a horizontal link like CPU0 L1D is coherent with CPU1 L1I?" or "do we have a MEMORY object?" or "what if coherency is not bidirectional (L1D snoops L2 but not vise versa). And you should maintain that links in case of CPU goes on/offline. And pulling info from that link net is nontrivial in user level, especially if "lshw" works in parallel with CPUx going offline.

But what you need is actually the answer on that 3 questions (see flags above). At least I don't see a reason for more complicated cache level relationship. Even the case BIG-LITTLE still is covered by flags.

- Leonid.

#8 lore raw
Quoted 8 lines · Leonid Yegoshin

Well, I prefer the collection of 3 flags:

flush_required - or flush to next level is required to force coherency
between this level and next after update of this level
invalidate_required - or invalidate is required to force coherency between
this level and next after update of next level
coherent_to_level - object is coherent with this level (only one domain of
coherency on this level is assumed)

A "flush" has always been an ambiguous term -- meaning anything from
"write-back", through "write-back+invalidate" to "invalidate". What is "flush" is supposed to exactly mean here? If specifically any of the two formers (the latter is obviously the other flag), then I suggest using the respective name, or otherwise if it is meant to be generic "do what is needed", then perhaps "synchronize" will work, like with the name of the SYNCI instruction?

Maciej

#9 lore raw
Quoted 10 lines · Maciej W. Rozycki
Quoted 8 lines · Leonid Yegoshin

Well, I prefer the collection of 3 flags:

flush_required - or flush to next level is required to force coherency
between this level and next after update of this level
invalidate_required - or invalidate is required to force coherency between
this level and next after update of next level
coherent_to_level - object is coherent with this level (only one domain of
coherency on this level is assumed)

Quoted 8 lines

A "flush" has always been an ambiguous term -- meaning anything from
"write-back", through "write-back+invalidate" to "invalidate". What is "flush" is supposed to exactly mean here? If specifically any of the two formers (the latter is obviously the other flag), then I suggest using the respective name, or otherwise if it is meant to be generic "do what is needed", then perhaps "synchronize" will work, like with the name of the SYNCI instruction?

Well, I am not expert in choosing names, you know. I just would like to make a distinguishing between "transfer data from this level to next one" - any way - writeback or write-back-invalidate, and "clear data in this level to be pulled on demand from next level".

This is an information purpose as Florian described, so details can be skipped. The only useful info here - some efforts are needed after event (see above) and that efforts are not cheap from performance point of view.

If we put here details then it is a long way because we need a lot of details, see my original post. However, I would like to differ "flush" and "invalidate" because it is triggered by different kind of event (from upstream or from downstream).

- Leonid.

#10 lore raw
Quoted 33 lines · Leonid Yegoshin
Quoted 15 lines · Maciej W. Rozycki
Quoted 11 lines · Leonid Yegoshin

Well, I prefer the collection of 3 flags:

flush_required - or flush to next level is required to force
coherency
between this level and next after update of this level
invalidate_required - or invalidate is required to force coherency
between
this level and next after update of next level
coherent_to_level - object is coherent with this level (only one
domain of
coherency on this level is assumed)

Quoted 8 lines

A "flush" has always been an ambiguous term -- meaning anything from
"write-back", through "write-back+invalidate" to "invalidate". What is "flush" is supposed to exactly mean here? If specifically any of the two formers (the latter is obviously the other flag), then I suggest using the respective name, or otherwise if it is meant to be generic "do what is needed", then perhaps "synchronize" will work, like with the name of the SYNCI instruction?

Well, I am not expert in choosing names, you know. I just would like to make a distinguishing between "transfer data from this level to next one" - any way - writeback or write-back-invalidate, and "clear data in this level to be pulled on demand from next level".

This is an information purpose as Florian described, so details can be skipped. The only useful info here - some efforts are needed after event (see above) and that efforts are not cheap from performance point of view.

Quoted 6 lines

If we put here details then it is a long way because we need a lot of details, see my original post. However, I would like to differ "flush" and "invalidate" because it is triggered by different kind of event (from upstream or from downstream).

- Leonid.

I can add in the flags mentioned by Leonid. However, I would suggest these flags be added in as a separate patch series as it will require modifications to the cacheinfo code to propagate the information to the sysfs.

Would it be ok to accept this patch series as is while I work with the cacheinfo maintainers to include these new flags?

-Justin

#11 lore raw
Quoted 40 lines · Justin Chen
Quoted 38 lines · Leonid Yegoshin
Quoted 15 lines · Maciej W. Rozycki
Quoted 11 lines · Leonid Yegoshin

Well, I prefer the collection of 3 flags:

flush_required - or flush to next level is required to force
coherency
between this level and next after update of this level
invalidate_required - or invalidate is required to force coherency
between
this level and next after update of next level
coherent_to_level - object is coherent with this level (only one
domain of
coherency on this level is assumed)

Quoted 8 lines

A "flush" has always been an ambiguous term -- meaning anything from
"write-back", through "write-back+invalidate" to "invalidate". What is "flush" is supposed to exactly mean here? If specifically any of the two formers (the latter is obviously the other flag), then I suggest using the respective name, or otherwise if it is meant to be generic "do what is needed", then perhaps "synchronize" will work, like with the name of the SYNCI instruction?

Well, I am not expert in choosing names, you know. I just would like to make a distinguishing between "transfer data from this level to next one" - any way - writeback or write-back-invalidate, and "clear data in this level to be pulled on demand from next level".

This is an information purpose as Florian described, so details can be skipped. The only useful info here - some efforts are needed after event (see above) and that efforts are not cheap from performance point of view.

If we put here details then it is a long way because we need a lot of details, see my original post. However, I would like to differ "flush" and "invalidate" because it is triggered by different kind of event (from upstream or from downstream).

Quoted 8 lines
Quoted 1 line

- Leonid.

I can add in the flags mentioned by Leonid. However, I would suggest these flags be added in as a separate patch series as it will require modifications to the cacheinfo code to propagate the information to the sysfs.

Would it be ok to accept this patch series as is while I work with the cacheinfo maintainers to include these new flags?

Seems entirely reasonable to me. You may want to make a new patch submission without "RFC", just to make it clear that this is a patch ready for review/acceptance.

Thanks!

Signature · 1 line
Florian
#12 lore raw
Quoted 45 lines · Florian Fainelli
Quoted 44 lines · Justin Chen
Quoted 31 lines · Leonid Yegoshin
Quoted 13 lines · Maciej W. Rozycki
Quoted 11 lines · Leonid Yegoshin

Well, I prefer the collection of 3 flags:

flush_required - or flush to next level is required to force
coherency
between this level and next after update of this level
invalidate_required - or invalidate is required to force coherency
between
this level and next after update of next level
coherent_to_level - object is coherent with this level (only one
domain of
coherency on this level is assumed)

Quoted 8 lines

A "flush" has always been an ambiguous term -- meaning anything from
"write-back", through "write-back+invalidate" to "invalidate". What is "flush" is supposed to exactly mean here? If specifically any of the two formers (the latter is obviously the other flag), then I suggest using the respective name, or otherwise if it is meant to be generic "do what is needed", then perhaps "synchronize" will work, like with the name of the SYNCI instruction?

Well, I am not expert in choosing names, you know. I just would like to make a distinguishing between "transfer data from this level to next one" - any way - writeback or write-back-invalidate, and "clear data in this level to be pulled on demand from next level".

This is an information purpose as Florian described, so details can be skipped. The only useful info here - some efforts are needed after event (see above) and that efforts are not cheap from performance point of view.

Quoted 6 lines

If we put here details then it is a long way because we need a lot of details, see my original post. However, I would like to differ "flush" and "invalidate" because it is triggered by different kind of event (from upstream or from downstream).

- Leonid.

I can add in the flags mentioned by Leonid. However, I would suggest these flags be added in as a separate patch series as it will require modifications to the cacheinfo code to propagate the information to the sysfs.

Quoted 7 lines
Quoted 2 lines

Would it be ok to accept this patch series as is while I work with the cacheinfo maintainers to include these new flags?

Seems entirely reasonable to me. You may want to make a new patch submission without "RFC", just to make it clear that this is a patch ready for review/acceptance.

Thanks!

I agree.

- Leonid.

#13 lore raw
In reply to Leonid Yegoshin
Quoted 9 lines · Leonid Yegoshin
Quoted 6 lines · Florian Fainelli

What Justin's patch is about is not so much about providing hints to user-space to bypass the kernel's own management of caches, (even though that has been used as an argument by the original introduction of cacheinfo), but more to provide some information to user-space about the cache topology and hierarchy.

I missed that, if it is for information purpose only, then it is OK.

Cache information can also be used for some software optimizations though I think GCC at this time doesn't do this kind of trickery.

Quoted 7 lines
Quoted 6 lines

Even though this is limited information this is still helpful to applications like lshw and others out there.

What would be needed from your perspective to get cacheinfo added to MIPS, shall we go back and address your initial comment about all the little details about coherency, snooping and re-filling strategy?

Quoted 7 lines

It depends. Initially, I thought Justin wants to replace arch/mips/mm/c-XXX.c with some universal approach and listed the missed stuff for that (I actually missed some more points in that list).

But for information purpose I don't have any more addition to Justin's patch... may be the coherency status, it has impact on performance:
coherency of L1D->L2, L2->memory and L1I->L1D/L2.

Coherency is hard to properly describe, there are many shades of grey between fully coherent and not coherent at all.

If we expose something to userspace which constitutes some kind of API then we really need to get it right because we can't change it arbitrarily later on.

Ralf

#14 lore raw
In reply to Leonid Yegoshin
Quoted 3 lines · Leonid Yegoshin

CACHE instruction is not available in user space, only SYNCI on MIPS R2+ for trampoline.
Any operation with CACHE requires a syscall.

Even worse, some older CPUs allow the execution of certain CACHE operations from user space. This is a feature which can be disabled by kernel.

Quoted 14 lines

As for SYNCI (trampoline from L1D->L1I) the following information in user space is needed:

1. L1 line size (available via RDHWR $x, $1). It is available now
directly from CPU, but may be better to supply from kernel because some cores has no that.

2. The flag that L1I is NOT coherent with L1D and SYNCI is needed and
available

The knowledge about L1/L2 sizes is not needed for regular application... well, if application wants to get advantage of cache sizes, well, in this case it can be supplied.

Quoted 7 lines

But it is unreliable because app may be rescheduled into different kind of core which has a different L1 size (in heterogeneous system, BTW). It can be fixed by setting affinity, of course (not sure - can it be reliably done in BIG/LITTLE approach). But that requires in application the knowledge and understanding of system CPU structure... well why we can allow all that stuff besides information purpose? It corrupts the all efforts and optimization in kernel about performance and powersaving.

Also let's not forget about CPUs like Octeons which have CPUs that don't quite fit in the usual scheme of doing things.

Ralf