linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Palmer Dabbelt <palmer@dabbelt.com>
To: zong.li@sifive.com
Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	zong.li@sifive.com, Paul Walmsley <paul.walmsley@sifive.com>
Subject: Re: [PATCH 3/3] riscv: Add cache information in AUX vector
Date: Thu, 20 Aug 2020 13:44:58 -0700 (PDT)	[thread overview]
Message-ID: <mhng-de0c1096-4f7f-45eb-b956-2d28188576e2@palmerdabbelt-glaptop1> (raw)
In-Reply-To: <aa7675dda78d3d595617d8d56b7fdd7f279a884f.1593766028.git.zong.li@sifive.com>

On Fri, 03 Jul 2020 01:57:55 PDT (-0700), zong.li@sifive.com wrote:
> There are no standard CSR registers to provide cache information, the
> way for RISC-V is to get this information from DT. Currently, AT_L1I_X,
> AT_L1D_X and AT_L2_X are present in glibc header, and sysconf syscall
> could use them to get information of cache through AUX vector.
>
> The result of 'getconf -a' as follows:
> LEVEL1_ICACHE_SIZE                 32768
> LEVEL1_ICACHE_ASSOC                8
> LEVEL1_ICACHE_LINESIZE             64
> LEVEL1_DCACHE_SIZE                 32768
> LEVEL1_DCACHE_ASSOC                8
> LEVEL1_DCACHE_LINESIZE             64
> LEVEL2_CACHE_SIZE                  2097152
> LEVEL2_CACHE_ASSOC                 32
> LEVEL2_CACHE_LINESIZE              64
>
> Signed-off-by: Zong Li <zong.li@sifive.com>
> ---
>  arch/riscv/include/asm/cacheinfo.h   | 14 ++++++++++++
>  arch/riscv/include/asm/elf.h         | 13 +++++++++++
>  arch/riscv/include/uapi/asm/auxvec.h | 23 ++++++++++++++++++-
>  arch/riscv/kernel/cacheinfo.c        | 33 +++++++++++++++++++++++++++-
>  4 files changed, 81 insertions(+), 2 deletions(-)
>  create mode 100644 arch/riscv/include/asm/cacheinfo.h
>
> diff --git a/arch/riscv/include/asm/cacheinfo.h b/arch/riscv/include/asm/cacheinfo.h
> new file mode 100644
> index 000000000000..ba179cd198b9
> --- /dev/null
> +++ b/arch/riscv/include/asm/cacheinfo.h
> @@ -0,0 +1,14 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Copyright (C) 2020 SiFive
> + */
> +
> +#ifndef _ASM_RISCV_CACHEINFO_H
> +#define _ASM_RISCV_CACHEINFO_H
> +
> +#include <linux/cacheinfo.h>
> +
> +uintptr_t get_cache_size(u32 level, enum cache_type type);
> +uintptr_t get_cache_geometry(u32 level, enum cache_type type);
> +
> +#endif /* _ASM_RISCV_CACHEINFO_H */
> diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h
> index d83a4efd052b..5c725e1df58b 100644
> --- a/arch/riscv/include/asm/elf.h
> +++ b/arch/riscv/include/asm/elf.h
> @@ -11,6 +11,7 @@
>  #include <uapi/asm/elf.h>
>  #include <asm/auxvec.h>
>  #include <asm/byteorder.h>
> +#include <asm/cacheinfo.h>
>
>  /*
>   * These are used to set parameters in the core dumps.
> @@ -61,6 +62,18 @@ extern unsigned long elf_hwcap;
>  do {								\
>  	NEW_AUX_ENT(AT_SYSINFO_EHDR,				\
>  		(elf_addr_t)current->mm->context.vdso);		\
> +	NEW_AUX_ENT(AT_L1I_CACHESIZE,				\
> +		get_cache_size(1, CACHE_TYPE_INST));		\
> +	NEW_AUX_ENT(AT_L1I_CACHEGEOMETRY,			\
> +		get_cache_geometry(1, CACHE_TYPE_INST));	\
> +	NEW_AUX_ENT(AT_L1D_CACHESIZE,				\
> +		get_cache_size(1, CACHE_TYPE_DATA));		\
> +	NEW_AUX_ENT(AT_L1D_CACHEGEOMETRY,			\
> +		get_cache_geometry(1, CACHE_TYPE_DATA));	\
> +	NEW_AUX_ENT(AT_L2_CACHESIZE,				\
> +		get_cache_size(2, CACHE_TYPE_UNIFIED));		\
> +	NEW_AUX_ENT(AT_L2_CACHEGEOMETRY,			\
> +		get_cache_geometry(2, CACHE_TYPE_UNIFIED));	\
>  } while (0)
>  #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
>  struct linux_binprm;
> diff --git a/arch/riscv/include/uapi/asm/auxvec.h b/arch/riscv/include/uapi/asm/auxvec.h
> index 22e0ae888406..32c73ba1d531 100644
> --- a/arch/riscv/include/uapi/asm/auxvec.h
> +++ b/arch/riscv/include/uapi/asm/auxvec.h
> @@ -10,7 +10,28 @@
>  /* vDSO location */
>  #define AT_SYSINFO_EHDR 33
>
> +/*
> + * The set of entries below represent more extensive information
> + * about the caches, in the form of two entry per cache type,
> + * one entry containing the cache size in bytes, and the other
> + * containing the cache line size in bytes in the bottom 16 bits
> + * and the cache associativity in the next 16 bits.
> + *
> + * The associativity is such that if N is the 16-bit value, the
> + * cache is N way set associative. A value if 0xffff means fully
> + * associative, a value of 1 means directly mapped.
> + *
> + * For all these fields, a value of 0 means that the information
> + * is not known.
> + */
> +#define AT_L1I_CACHESIZE	40
> +#define AT_L1I_CACHEGEOMETRY	41
> +#define AT_L1D_CACHESIZE	42
> +#define AT_L1D_CACHEGEOMETRY	43
> +#define AT_L2_CACHESIZE		44
> +#define AT_L2_CACHEGEOMETRY	45
> +
>  /* entries in ARCH_DLINFO */
> -#define AT_VECTOR_SIZE_ARCH	1
> +#define AT_VECTOR_SIZE_ARCH	7
>
>  #endif /* _UAPI_ASM_RISCV_AUXVEC_H */
> diff --git a/arch/riscv/kernel/cacheinfo.c b/arch/riscv/kernel/cacheinfo.c
> index cdd35e53fd98..263335def44b 100644
> --- a/arch/riscv/kernel/cacheinfo.c
> +++ b/arch/riscv/kernel/cacheinfo.c
> @@ -3,10 +3,41 @@
>   * Copyright (C) 2017 SiFive
>   */
>
> -#include <linux/cacheinfo.h>
>  #include <linux/cpu.h>
>  #include <linux/of.h>
>  #include <linux/of_device.h>
> +#include <asm/cacheinfo.h>
> +
> +static struct cacheinfo *get_cacheinfo(u32 level, enum cache_type type)
> +{
> +	struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(smp_processor_id());
> +	struct cacheinfo *this_leaf;
> +	int index;
> +
> +	for (index = 0; index < this_cpu_ci->num_leaves; index++) {
> +		this_leaf = this_cpu_ci->info_list + index;
> +		if (this_leaf->level == level && this_leaf->type == type)
> +			return this_leaf;
> +	}
> +
> +	return 0;
> +}
> +
> +uintptr_t get_cache_size(u32 level, enum cache_type type)
> +{
> +	struct cacheinfo *this_leaf = get_cacheinfo(level, type);
> +
> +	return this_leaf ? this_leaf->size : 0;
> +}
> +
> +uintptr_t get_cache_geometry(u32 level, enum cache_type type)
> +{
> +	struct cacheinfo *this_leaf = get_cacheinfo(level, type);
> +	uintptr_t ret = (this_leaf->ways_of_associativity << 16 |
> +			 this_leaf->coherency_line_size);
> +
> +	return this_leaf ? ret : 0;
> +}
>
>  static void ci_leaf_init(struct cacheinfo *this_leaf, enum cache_type type,
>  			 unsigned int level, unsigned int size,

Reviewed-by: Palmer Dabbelt <palmerdabbelt@google.com>

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2020-08-20 20:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-03  8:57 [PATCH 0/3] Get cache information from userland Zong Li
2020-07-03  8:57 ` [PATCH 1/3] riscv: Set more data to cacheinfo Zong Li
2020-08-20 20:44   ` Palmer Dabbelt
2020-07-03  8:57 ` [PATCH 2/3] riscv: Define AT_VECTOR_SIZE_ARCH for ARCH_DLINFO Zong Li
2020-08-20 20:44   ` Palmer Dabbelt
2020-07-03  8:57 ` [PATCH 3/3] riscv: Add cache information in AUX vector Zong Li
2020-08-20 20:44   ` Palmer Dabbelt [this message]
2020-07-27  3:03 ` [PATCH 0/3] Get cache information from userland Zong Li
2020-08-20 20:45 ` Palmer Dabbelt
2020-08-27  8:22   ` Zong Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=mhng-de0c1096-4f7f-45eb-b956-2d28188576e2@palmerdabbelt-glaptop1 \
    --to=palmer@dabbelt.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=paul.walmsley@sifive.com \
    --cc=zong.li@sifive.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).