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 5/8] counter: microchip-tcp-capture: 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.

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: 1/6 up/down: 12/-68 (-56)
Function old new delta
mchp_tc_count_function_write 1016 1028 +12
mchp_tc_count_action_write 204 196 -8
mchp_tc_probe 1376 1364 -12
mchp_tc_count_signal_read 360 348 -12
mchp_tc_count_read 264 252 -12
mchp_tc_count_function_read 108 96 -12
mchp_tc_count_action_read 392 380 -12
Total: Before=5920, After=5864, chg -0.95%

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/counter/microchip-tcb-capture.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
index 0ab1b2716784..031e79f5f06a 100644
--- a/drivers/counter/microchip-tcb-capture.c
+++ b/drivers/counter/microchip-tcb-capture.c
@@ -32,6 +32,11 @@ struct mchp_tc_data {
bool trig_inverted;
};

+static inline struct mchp_tc_data *mchp_tc_from_counter(struct counter_device *counter)
+{
+ return container_of(counter, struct mchp_tc_data, counter);
+}
+
static const enum counter_function mchp_tc_count_functions[] = {
COUNTER_FUNCTION_INCREASE,
COUNTER_FUNCTION_QUADRATURE_X4,
@@ -72,7 +77,7 @@ static int mchp_tc_count_function_read(struct counter_device *counter,
struct counter_count *count,
enum counter_function *function)
{
- struct mchp_tc_data *const priv = counter->priv;
+ struct mchp_tc_data *const priv = mchp_tc_from_counter(counter);

if (priv->qdec_mode)
*function = COUNTER_FUNCTION_QUADRATURE_X4;
@@ -86,7 +91,7 @@ static int mchp_tc_count_function_write(struct counter_device *counter,
struct counter_count *count,
enum counter_function function)
{
- struct mchp_tc_data *const priv = counter->priv;
+ struct mchp_tc_data *const priv = mchp_tc_from_counter(counter);
u32 bmr, cmr;

regmap_read(priv->regmap, ATMEL_TC_BMR, &bmr);
@@ -148,7 +153,7 @@ static int mchp_tc_count_signal_read(struct counter_device *counter,
struct counter_signal *signal,
enum counter_signal_level *lvl)
{
- struct mchp_tc_data *const priv = counter->priv;
+ struct mchp_tc_data *const priv = mchp_tc_from_counter(counter);
bool sigstatus;
u32 sr;

@@ -169,7 +174,7 @@ static int mchp_tc_count_action_read(struct counter_device *counter,
struct counter_synapse *synapse,
enum counter_synapse_action *action)
{
- struct mchp_tc_data *const priv = counter->priv;
+ struct mchp_tc_data *const priv = mchp_tc_from_counter(counter);
u32 cmr;

regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr);
@@ -197,7 +202,7 @@ static int mchp_tc_count_action_write(struct counter_device *counter,
struct counter_synapse *synapse,
enum counter_synapse_action action)
{
- struct mchp_tc_data *const priv = counter->priv;
+ struct mchp_tc_data *const priv = mchp_tc_from_counter(counter);
u32 edge = ATMEL_TC_ETRGEDG_NONE;

/* QDEC mode is rising edge only */
@@ -230,7 +235,7 @@ static int mchp_tc_count_action_write(struct counter_device *counter,
static int mchp_tc_count_read(struct counter_device *counter,
struct counter_count *count, u64 *val)
{
- struct mchp_tc_data *const priv = counter->priv;
+ struct mchp_tc_data *const priv = mchp_tc_from_counter(counter);
u32 cnt;

regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CV), &cnt);
@@ -369,7 +374,6 @@ static int mchp_tc_probe(struct platform_device *pdev)
priv->counter.counts = mchp_tc_counts;
priv->counter.num_signals = ARRAY_SIZE(mchp_tc_count_signals);
priv->counter.signals = mchp_tc_count_signals;
- priv->counter.priv = priv;

return devm_counter_register(&pdev->dev, &priv->counter);
}
--
2.33.0
\
 
 \ /
  Last update: 2021-12-21 11:47    [W:0.081 / U:0.432 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site