2021-06-05 16:04:35

by Rikard Falkeborn

[permalink] [raw]
Subject: [PATCH 0/4] perf/x86/intel: Constify static structs

Constify a number of static structs which are not modified to allow the
compiler to place them in read-only memory. All in all, it moves ~25kB
to read-only memory (if looking at o-files).

Rikard Falkeborn (4):
perf/x86/intel/uncore: Constify intel_uncore_ops
perf/x86/intel: Constify static attribute_group structs
perf/x86/intel/uncore: Constify freerunning_counters
perf/x86/intel/uncore: Constify unmodified static extra_reg structs

arch/x86/events/intel/core.c | 8 +-
arch/x86/events/intel/cstate.c | 10 +--
arch/x86/events/intel/pt.c | 4 +-
arch/x86/events/intel/uncore.h | 6 +-
arch/x86/events/intel/uncore_discovery.c | 6 +-
arch/x86/events/intel/uncore_nhmex.c | 16 ++--
arch/x86/events/intel/uncore_snb.c | 20 ++---
arch/x86/events/intel/uncore_snbep.c | 102 +++++++++++------------
8 files changed, 86 insertions(+), 86 deletions(-)

--
2.31.1


2021-06-05 16:04:35

by Rikard Falkeborn

[permalink] [raw]
Subject: [PATCH 2/4] perf/x86/intel: Constify static attribute_group structs

These either have their address put in an array of pointers to const
attribute structs, or (in uncore_snb.c and uncore_snbep.c) have their
address assigned to at pointer to const field in the intel_uncore_type
struct.

Signed-off-by: Rikard Falkeborn <[email protected]>
---
arch/x86/events/intel/core.c | 8 ++++----
arch/x86/events/intel/cstate.c | 10 +++++-----
arch/x86/events/intel/pt.c | 4 ++--
arch/x86/events/intel/uncore_snb.c | 2 +-
arch/x86/events/intel/uncore_snbep.c | 2 +-
5 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index e28892270c58..b07d832f304e 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -5164,12 +5164,12 @@ static struct attribute_group group_events_tsx = {
.is_visible = tsx_is_visible,
};

-static struct attribute_group group_caps_gen = {
+static const struct attribute_group group_caps_gen = {
.name = "caps",
.attrs = intel_pmu_caps_attrs,
};

-static struct attribute_group group_caps_lbr = {
+static const struct attribute_group group_caps_lbr = {
.name = "caps",
.attrs = lbr_attrs,
.is_visible = lbr_is_visible,
@@ -5185,7 +5185,7 @@ static struct attribute_group group_format_extra_skl = {
.is_visible = exra_is_visible,
};

-static struct attribute_group group_default = {
+static const struct attribute_group group_default = {
.attrs = intel_pmu_attrs,
.is_visible = default_is_visible,
};
@@ -5364,7 +5364,7 @@ static struct attribute *intel_hybrid_cpus_attrs[] = {
NULL,
};

-static struct attribute_group hybrid_group_cpus = {
+static const struct attribute_group hybrid_group_cpus = {
.attrs = intel_hybrid_cpus_attrs,
};

diff --git a/arch/x86/events/intel/cstate.c b/arch/x86/events/intel/cstate.c
index 433399069e27..089f71ac83f5 100644
--- a/arch/x86/events/intel/cstate.c
+++ b/arch/x86/events/intel/cstate.c
@@ -187,7 +187,7 @@ static struct attribute *attrs_empty[] = {
* "events" group (with empty attrs) before updating
* it with detected events.
*/
-static struct attribute_group core_events_attr_group = {
+static const struct attribute_group core_events_attr_group = {
.name = "events",
.attrs = attrs_empty,
};
@@ -198,7 +198,7 @@ static struct attribute *core_format_attrs[] = {
NULL,
};

-static struct attribute_group core_format_attr_group = {
+static const struct attribute_group core_format_attr_group = {
.name = "format",
.attrs = core_format_attrs,
};
@@ -211,7 +211,7 @@ static struct attribute *cstate_cpumask_attrs[] = {
NULL,
};

-static struct attribute_group cpumask_attr_group = {
+static const struct attribute_group cpumask_attr_group = {
.attrs = cstate_cpumask_attrs,
};

@@ -266,7 +266,7 @@ static struct perf_msr pkg_msr[] = {
[PERF_CSTATE_PKG_C10_RES] = { MSR_PKG_C10_RESIDENCY, &group_cstate_pkg_c10, test_msr },
};

-static struct attribute_group pkg_events_attr_group = {
+static const struct attribute_group pkg_events_attr_group = {
.name = "events",
.attrs = attrs_empty,
};
@@ -276,7 +276,7 @@ static struct attribute *pkg_format_attrs[] = {
&format_attr_pkg_event.attr,
NULL,
};
-static struct attribute_group pkg_format_attr_group = {
+static const struct attribute_group pkg_format_attr_group = {
.name = "format",
.attrs = pkg_format_attrs,
};
diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c
index 915847655c06..83ccf106ed13 100644
--- a/arch/x86/events/intel/pt.c
+++ b/arch/x86/events/intel/pt.c
@@ -128,7 +128,7 @@ static struct attribute *pt_formats_attr[] = {
NULL,
};

-static struct attribute_group pt_format_group = {
+static const struct attribute_group pt_format_group = {
.name = "format",
.attrs = pt_formats_attr,
};
@@ -165,7 +165,7 @@ static struct attribute *pt_timing_attr[] = {
NULL,
};

-static struct attribute_group pt_timing_group = {
+static const struct attribute_group pt_timing_group = {
.attrs = pt_timing_attr,
};

diff --git a/arch/x86/events/intel/uncore_snb.c b/arch/x86/events/intel/uncore_snb.c
index 5826cff568f4..3eff6f1a5b99 100644
--- a/arch/x86/events/intel/uncore_snb.c
+++ b/arch/x86/events/intel/uncore_snb.c
@@ -369,7 +369,7 @@ static struct attribute *icl_uncore_clock_formats_attr[] = {
NULL,
};

-static struct attribute_group icl_uncore_clock_format_group = {
+static const struct attribute_group icl_uncore_clock_format_group = {
.name = "format",
.attrs = icl_uncore_clock_formats_attr,
};
diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c
index 43eabe8d37dc..b5b22fe473d8 100644
--- a/arch/x86/events/intel/uncore_snbep.c
+++ b/arch/x86/events/intel/uncore_snbep.c
@@ -4001,7 +4001,7 @@ static struct attribute *skx_uncore_pcu_formats_attr[] = {
NULL,
};

-static struct attribute_group skx_uncore_pcu_format_group = {
+static const struct attribute_group skx_uncore_pcu_format_group = {
.name = "format",
.attrs = skx_uncore_pcu_formats_attr,
};
--
2.31.1

2021-06-05 16:05:40

by Rikard Falkeborn

[permalink] [raw]
Subject: [PATCH 3/4] perf/x86/intel/uncore: Constify freerunning_counters

These are never modified, so make them const to allow the compiler to
put them in read-only memory.

Signed-off-by: Rikard Falkeborn <[email protected]>
---
arch/x86/events/intel/uncore.h | 4 ++--
arch/x86/events/intel/uncore_snb.c | 6 +++---
arch/x86/events/intel/uncore_snbep.c | 14 +++++++-------
3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/arch/x86/events/intel/uncore.h b/arch/x86/events/intel/uncore.h
index 83b25a7b8c27..6a7f0104bb38 100644
--- a/arch/x86/events/intel/uncore.h
+++ b/arch/x86/events/intel/uncore.h
@@ -79,7 +79,7 @@ struct intel_uncore_type {
struct intel_uncore_pmu *pmus;
const struct intel_uncore_ops *ops;
struct uncore_event_desc *event_descs;
- struct freerunning_counters *freerunning;
+ const struct freerunning_counters *freerunning;
const struct attribute_group *attr_groups[4];
const struct attribute_group **attr_update;
struct pmu *pmu; /* for custom pmu ops */
@@ -175,7 +175,7 @@ struct freerunning_counters {
unsigned int box_offset;
unsigned int num_counters;
unsigned int bits;
- unsigned *box_offsets;
+ const unsigned *box_offsets;
};

struct intel_uncore_topology {
diff --git a/arch/x86/events/intel/uncore_snb.c b/arch/x86/events/intel/uncore_snb.c
index 3eff6f1a5b99..475e48b7a686 100644
--- a/arch/x86/events/intel/uncore_snb.c
+++ b/arch/x86/events/intel/uncore_snb.c
@@ -603,7 +603,7 @@ enum perf_snb_uncore_imc_freerunning_types {
SNB_PCI_UNCORE_IMC_FREERUNNING_TYPE_MAX,
};

-static struct freerunning_counters snb_uncore_imc_freerunning[] = {
+static const struct freerunning_counters snb_uncore_imc_freerunning[] = {
[SNB_PCI_UNCORE_IMC_DATA_READS] = { SNB_UNCORE_PCI_IMC_DATA_READS_BASE,
0x0, 0x0, 1, 32 },
[SNB_PCI_UNCORE_IMC_DATA_WRITES] = { SNB_UNCORE_PCI_IMC_DATA_WRITES_BASE,
@@ -1344,13 +1344,13 @@ enum perf_tgl_uncore_imc_freerunning_types {
TGL_MMIO_UNCORE_IMC_FREERUNNING_TYPE_MAX
};

-static struct freerunning_counters tgl_l_uncore_imc_freerunning[] = {
+static const struct freerunning_counters tgl_l_uncore_imc_freerunning[] = {
[TGL_MMIO_UNCORE_IMC_DATA_TOTAL] = { 0x5040, 0x0, 0x0, 1, 64 },
[TGL_MMIO_UNCORE_IMC_DATA_READ] = { 0x5058, 0x0, 0x0, 1, 64 },
[TGL_MMIO_UNCORE_IMC_DATA_WRITE] = { 0x50A0, 0x0, 0x0, 1, 64 },
};

-static struct freerunning_counters tgl_uncore_imc_freerunning[] = {
+static const struct freerunning_counters tgl_uncore_imc_freerunning[] = {
[TGL_MMIO_UNCORE_IMC_DATA_TOTAL] = { 0xd840, 0x0, 0x0, 1, 64 },
[TGL_MMIO_UNCORE_IMC_DATA_READ] = { 0xd858, 0x0, 0x0, 1, 64 },
[TGL_MMIO_UNCORE_IMC_DATA_WRITE] = { 0xd8A0, 0x0, 0x0, 1, 64 },
diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c
index b5b22fe473d8..507bb83e1463 100644
--- a/arch/x86/events/intel/uncore_snbep.c
+++ b/arch/x86/events/intel/uncore_snbep.c
@@ -3885,7 +3885,7 @@ enum perf_uncore_iio_freerunning_type_id {
};


-static struct freerunning_counters skx_iio_freerunning[] = {
+static const struct freerunning_counters skx_iio_freerunning[] = {
[SKX_IIO_MSR_IOCLK] = { 0xa45, 0x1, 0x20, 1, 36 },
[SKX_IIO_MSR_BW] = { 0xb00, 0x1, 0x10, 8, 36 },
[SKX_IIO_MSR_UTIL] = { 0xb08, 0x1, 0x10, 8, 36 },
@@ -4588,7 +4588,7 @@ enum perf_uncore_snr_iio_freerunning_type_id {
SNR_IIO_FREERUNNING_TYPE_MAX,
};

-static struct freerunning_counters snr_iio_freerunning[] = {
+static const struct freerunning_counters snr_iio_freerunning[] = {
[SNR_IIO_MSR_IOCLK] = { 0x1eac, 0x1, 0x10, 1, 48 },
[SNR_IIO_MSR_BW_IN] = { 0x1f00, 0x1, 0x10, 8, 48 },
};
@@ -4931,7 +4931,7 @@ enum perf_uncore_snr_imc_freerunning_type_id {
SNR_IMC_FREERUNNING_TYPE_MAX,
};

-static struct freerunning_counters snr_imc_freerunning[] = {
+static const struct freerunning_counters snr_imc_freerunning[] = {
[SNR_IMC_DCLK] = { 0x22b0, 0x0, 0, 1, 48 },
[SNR_IMC_DDR] = { 0x2290, 0x8, 0, 2, 48 },
};
@@ -5153,15 +5153,15 @@ enum perf_uncore_icx_iio_freerunning_type_id {
ICX_IIO_FREERUNNING_TYPE_MAX,
};

-static unsigned icx_iio_clk_freerunning_box_offsets[] = {
+static const unsigned icx_iio_clk_freerunning_box_offsets[] = {
0x0, 0x20, 0x40, 0x90, 0xb0, 0xd0,
};

-static unsigned icx_iio_bw_freerunning_box_offsets[] = {
+static const unsigned icx_iio_bw_freerunning_box_offsets[] = {
0x0, 0x10, 0x20, 0x90, 0xa0, 0xb0,
};

-static struct freerunning_counters icx_iio_freerunning[] = {
+static const struct freerunning_counters icx_iio_freerunning[] = {
[ICX_IIO_MSR_IOCLK] = { 0xa55, 0x1, 0x20, 1, 48, icx_iio_clk_freerunning_box_offsets },
[ICX_IIO_MSR_BW_IN] = { 0xaa0, 0x1, 0x10, 8, 48, icx_iio_bw_freerunning_box_offsets },
};
@@ -5443,7 +5443,7 @@ enum perf_uncore_icx_imc_freerunning_type_id {
ICX_IMC_FREERUNNING_TYPE_MAX,
};

-static struct freerunning_counters icx_imc_freerunning[] = {
+static const struct freerunning_counters icx_imc_freerunning[] = {
[ICX_IMC_DCLK] = { 0x22b0, 0x0, 0, 1, 48 },
[ICX_IMC_DDR] = { 0x2290, 0x8, 0, 2, 48 },
[ICX_IMC_DDRT] = { 0x22a0, 0x8, 0, 2, 48 },
--
2.31.1