lkml.org 
[lkml]   [2021]   [Dec]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/8] counter: ftm-quaddec: Use container_of instead of struct counter_device::priv
Date
Using counter->priv is a memory read and so more expensive than
container_of which is only an addition. (In this case even a noop
because the offset is 0.)

So container_of is expected to be a tad faster, it's type-safe, and
produces smaller code (ARCH=arm allmodconfig):

add/remove: 0/0 grow/shrink: 0/5 up/down: 0/-60 (-60)
Function old new delta
ftm_quaddec_set_prescaler 612 600 -12
ftm_quaddec_probe 596 584 -12
ftm_quaddec_get_prescaler 156 144 -12
ftm_quaddec_count_write 232 220 -12
ftm_quaddec_count_read 152 140 -12
Total: Before=5096, After=5036, chg -1.18%

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/counter/ftm-quaddec.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
index 5ef0478709cd..b58a4f54e97b 100644
--- a/drivers/counter/ftm-quaddec.c
+++ b/drivers/counter/ftm-quaddec.c
@@ -33,6 +33,11 @@ struct ftm_quaddec {
struct mutex ftm_quaddec_mutex;
};

+static inline struct ftm_quaddec *ftm_from_counter(struct counter_device *counter)
+{
+ return container_of(counter, struct ftm_quaddec, counter);
+}
+
static void ftm_read(struct ftm_quaddec *ftm, uint32_t offset, uint32_t *data)
{
if (ftm->big_endian)
@@ -118,7 +123,7 @@ static void ftm_quaddec_disable(void *ftm)
static int ftm_quaddec_get_prescaler(struct counter_device *counter,
struct counter_count *count, u32 *cnt_mode)
{
- struct ftm_quaddec *ftm = counter->priv;
+ struct ftm_quaddec *ftm = ftm_from_counter(counter);
uint32_t scflags;

ftm_read(ftm, FTM_SC, &scflags);
@@ -131,7 +136,7 @@ static int ftm_quaddec_get_prescaler(struct counter_device *counter,
static int ftm_quaddec_set_prescaler(struct counter_device *counter,
struct counter_count *count, u32 cnt_mode)
{
- struct ftm_quaddec *ftm = counter->priv;
+ struct ftm_quaddec *ftm = ftm_from_counter(counter);

mutex_lock(&ftm->ftm_quaddec_mutex);

@@ -162,7 +167,7 @@ static int ftm_quaddec_count_read(struct counter_device *counter,
struct counter_count *count,
u64 *val)
{
- struct ftm_quaddec *const ftm = counter->priv;
+ struct ftm_quaddec *const ftm = ftm_from_counter(counter);
uint32_t cntval;

ftm_read(ftm, FTM_CNT, &cntval);
@@ -176,7 +181,7 @@ static int ftm_quaddec_count_write(struct counter_device *counter,
struct counter_count *count,
const u64 val)
{
- struct ftm_quaddec *const ftm = counter->priv;
+ struct ftm_quaddec *const ftm = ftm_from_counter(counter);

if (val != 0) {
dev_warn(&ftm->pdev->dev, "Can only accept '0' as new counter value\n");
@@ -292,7 +297,6 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
ftm->counter.num_counts = 1;
ftm->counter.signals = ftm_quaddec_signals;
ftm->counter.num_signals = ARRAY_SIZE(ftm_quaddec_signals);
- ftm->counter.priv = ftm;

mutex_init(&ftm->ftm_quaddec_mutex);

--
2.33.0
\
 
 \ /
  Last update: 2021-12-21 11:47    [W:0.058 / U:0.744 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site