dpll: zl3073x: Allow to use custom phase measure averaging factor
Subsystems (6)
Ivan Vecera
maintainerPATCH 1/1 dpll: zl3073x: Allow to use custom phase measure averaging factor
The DPLL phase measurement block uses an exponential moving average, calculated using the following equation:
2^N - 1 1curr_avg = prev_avg * --------- + new_val * -----
2^N 2^N
Where curr_avg is phase offset reported by the firmware to the driver, prev_avg is previous averaged value and new_val is currently measured value for particular reference.
New measurements are taken approximately 40 Hz or at the frequency of the reference (whichever is lower).
The driver currently uses the averaging factor N=2 which prioritizes a fast response time to track dynamic changes in the phase. But for applications requiring a very stable and precise reading of the average phase offset, and where rapid changes are not expected, a higher factor would be appropriate.
Add devlink device parameter phase_offset_avg_factor to allow a user set tune the averaging factor via devlink interface.
--- Documentation/networking/devlink/zl3073x.rst | 4 ++ drivers/dpll/zl3073x/core.c | 6 +- drivers/dpll/zl3073x/core.h | 8 ++- drivers/dpll/zl3073x/devlink.c | 67 ++++++++++++++++++++ 4 files changed, 82 insertions(+), 3 deletions(-)
Documentation/networking/devlink/zl3073x.rst +4 -0
@@ -20,6 +20,10 @@ Parameters - driverinit - Set the clock ID that is used by the driver for registering DPLL devices and pins. + * - ``phase_offset_avg_factor`` + - runtime + - Set the factor for the exponential moving average used by DPLL phase + measurement block. The value has to be in range <0, 15>. Info versions =============
drivers/dpll/zl3073x/core.c +5 -1
@@ -915,7 +915,8 @@ zl3073x_dev_phase_meas_setup(struct zl3073x_dev *zldev, int num_channels)/* Setup phase measurement averaging factor */ dpll_meas_ctrl &= ~ZL_DPLL_MEAS_CTRL_AVG_FACTOR ; - dpll_meas_ctrl |=FIELD_PREP (ZL_DPLL_MEAS_CTRL_AVG_FACTOR ,3 ); + dpll_meas_ctrl |=FIELD_PREP (ZL_DPLL_MEAS_CTRL_AVG_FACTOR , + zldev->phase_avg_factor);/* Enable DPLL measurement block */ dpll_meas_ctrl |=ZL_DPLL_MEAS_CTRL_EN ;
@@ -991,6 +992,9 @@ int zl3073x_dev_probe(struct zl3073x_dev *zldev,*/ zldev->clock_id =get_random_u64 (); +/* Default phase offset averaging factor */ + zldev->phase_avg_factor =3 ; +/* Initialize mutex for operations where multiple reads, writes * and/or polls are required to be done atomically. */
drivers/dpll/zl3073x/core.h +6 -2
@@ -67,19 +67,19 @@ struct zl3073x_synth {* @dev: pointer to device * @regmap: regmap to access device registers * @multiop_lock: to serialize multiple register operations -* @clock_id: clock id of the device * @ref: array of input references' invariants * @out: array of outs' invariants * @synth: array of synths' invariants * @dplls: list of DPLLs * @kworker: thread for periodic work * @work: periodic work +* @clock_id: clock id of the device +* @phase_avg_factor: phase offset measurement averaging factor */ struct zl3073x_dev {struct device *dev;struct regmap *regmap;struct mutex multiop_lock; -u64 clock_id;/* Invariants */ struct zl3073x_ref ref[ZL3073X_NUM_REFS ];
@@ -92,6 +92,10 @@ struct zl3073x_dev {/* Monitor */ struct kthread_worker *kworker;struct kthread_delayed_work work; + +/* Devlink parameters */ +u64 clock_id; +u8 phase_avg_factor; };struct zl3073x_chip_info {
drivers/dpll/zl3073x/devlink.c +67 -0
77 lines not on this page · raw message
Signature · 1 line
2.49.1
Quoted 23 lines · Ivan Vecera
The DPLL phase measurement block uses an exponential moving average, calculated using the following equation:
2^N - 1 1
curr_avg=prev_avg* --------- +new_val* -----
2^N 2^NWhere
curr_avgis phase offset reported by the firmware to the driver,prev_avgis previous averaged value andnew_valis currently measured value for particular reference.New measurements are taken approximately 40 Hz or at the frequency of the reference (whichever is lower).
The driver currently uses the averaging factor N=2 which prioritizes a fast response time to track dynamic changes in the phase. But for applications requiring a very stable and precise reading of the average phase offset, and where rapid changes are not expected, a higher factor would be appropriate.
Add devlink device parameter
phase_offset_avg_factorto allow a user set tune the averaging factor via devlink interface.
Quoted 9 lines
Tested-by Prathosh Satish <[email protected]>Signed-off-by Ivan Vecera <[email protected]>--- Documentation/networking/devlink/zl3073x.rst | 4 ++ drivers/dpll/zl3073x/core.c | 6 +- drivers/dpll/zl3073x/core.h | 8 ++- drivers/dpll/zl3073x/devlink.c | 67 ++++++++++++++++++++ 4 files changed, 82 insertions(+), 3 deletions(-)
looks good,
drivers/dpll/zl3073x/devlink.c zl3073x_devlink_param_clock_id_validate(struct devlink *devlink, u32 id, · line 251
Quoted 6 lines
drivers/dpll/zl3073x/devlink.c +6
-0+static int +zl3073x_devlink_param_phase_avg_factor_validate (struct devlink *devlink,u32 id, +union devlink_param_value val, +struct netlink_ext_ack *extack) +{ +return (val.vu8 <16 ) ?0 : -EINVAL ;
nit: redundant params, not worth respining
Vadim Fedorenko
maintainerQuoted 25 lines · Ivan Vecera
The DPLL phase measurement block uses an exponential moving average, calculated using the following equation:
2^N - 1 1
curr_avg=prev_avg* --------- +new_val* -----
2^N 2^NWhere
curr_avgis phase offset reported by the firmware to the driver,prev_avgis previous averaged value andnew_valis currently measured value for particular reference.New measurements are taken approximately 40 Hz or at the frequency of the reference (whichever is lower).
The driver currently uses the averaging factor N=2 which prioritizes a fast response time to track dynamic changes in the phase. But for applications requiring a very stable and precise reading of the average phase offset, and where rapid changes are not expected, a higher factor would be appropriate.
Add devlink device parameter
phase_offset_avg_factorto allow a user set tune the averaging factor via devlink interface.Tested-by Prathosh Satish <[email protected]>Signed-off-by Ivan Vecera <[email protected]>
[...]
Quoted 10 lines
drivers/dpll/zl3073x/devlink.c +10
-0+static int +zl3073x_devlink_param_phase_avg_factor_set (struct devlink *devlink,u32 id, +struct devlink_param_gset_ctx *ctx, +struct netlink_ext_ack *extack) +{ +struct zl3073x_dev *zldev =devlink_priv (devlink); +u8 avg_factor, dpll_meas_ctrl; +int rc; + +/* Read DPLL phase measurement control register */
drivers/dpll/zl3073x/devlink.c zl3073x_devlink_param_clock_id_validate(struct devlink *devlink, u32 id, · line 232
Quoted 10 lines
drivers/dpll/zl3073x/devlink.c +10
-0+ rc =zl3073x_read_u8 (zldev,ZL_REG_DPLL_MEAS_CTRL , &dpll_meas_ctrl); +if (rc) +return rc; + +/* Convert requested factor to register value */ +if (ctx->val.vu8 <15 ) + avg_factor = ctx->val.vu8 +1 ; +else + avg_factor =0 ; +
This looks like avg_factor = (ctx->val.vu8 + 1) & 0x0f;
The same logic can be applied for get() function assuming we are aware of unsigned roll-over...
Ivan Vecera
maintainerQuoted 46 lines · Vadim Fedorenko
Quoted 25 lines · Ivan Vecera
The DPLL phase measurement block uses an exponential moving average, calculated using the following equation:
2^N - 1 1
curr_avg=prev_avg* --------- +new_val* -----
2^N 2^NWhere
curr_avgis phase offset reported by the firmware to the driver,prev_avgis previous averaged value andnew_valis currently measured value for particular reference.New measurements are taken approximately 40 Hz or at the frequency of the reference (whichever is lower).
The driver currently uses the averaging factor N=2 which prioritizes a fast response time to track dynamic changes in the phase. But for applications requiring a very stable and precise reading of the average phase offset, and where rapid changes are not expected, a higher factor would be appropriate.
Add devlink device parameter
phase_offset_avg_factorto allow a user set tune the averaging factor via devlink interface.Tested-by Prathosh Satish <[email protected]>Signed-off-by Ivan Vecera <[email protected]>[...]
Quoted 17 lines
(quoted diff) +2
-0+static int +zl3073x_devlink_param_phase_avg_factor_set(struct devlink *devlink,u32 id,
+ structdevlink_param_gset_ctx*ctx, + structnetlink_ext_ack*extack)drivers/dpll/zl3073x/devlink.c +12
-0+{ + struct zl3073x_dev *zldev = devlink_priv(devlink); + u8 avg_factor, dpll_meas_ctrl; + int rc; + + /* Read DPLL phase measurement control register */ + rc = zl3073x_read_u8(zldev, ZL_REG_DPLL_MEAS_CTRL, &dpll_meas_ctrl); + if (rc) + return rc; + + /* Convert requested factor to register value */ + if (ctx->val.vu8 < 15)
Quoted 8 lines
Quoted 4 lines
+
avg_factor=ctx->val.vu8+ 1;
+ else
+avg_factor= 0;
+This looks like
avg_factor= (ctx->val.vu8+ 1) &0x0f;
The same logic can be applied forget()function assuming we are aware of unsigned roll-over...
Yes, I know about this trick but I wanted to use more readable code and leave potential optimization to the compiler.
Ivan
Quoted 37 lines · Ivan Vecera
The DPLL phase measurement block uses an exponential moving average, calculated using the following equation:
2^N - 1 1
curr_avg=prev_avg* --------- +new_val* -----
2^N 2^NWhere
curr_avgis phase offset reported by the firmware to the driver,prev_avgis previous averaged value andnew_valis currently measured value for particular reference.New measurements are taken approximately 40 Hz or at the frequency of the reference (whichever is lower).
The driver currently uses the averaging factor N=2 which prioritizes a fast response time to track dynamic changes in the phase. But for applications requiring a very stable and precise reading of the average phase offset, and where rapid changes are not expected, a higher factor would be appropriate.
Add devlink device parameter
phase_offset_avg_factorto allow a user set tune the averaging factor via devlink interface.Tested-by Prathosh Satish <[email protected]>Signed-off-by Ivan Vecera <[email protected]>--- Documentation/networking/devlink/zl3073x.rst | 4 ++ drivers/dpll/zl3073x/core.c | 6 +- drivers/dpll/zl3073x/core.h | 8 ++- drivers/dpll/zl3073x/devlink.c | 67 ++++++++++++++++++++ 4 files changed, 82 insertions(+), 3 deletions(-)Documentation/networking/devlink/zl3073x.rst +0
-0
Documentation/networking/devlink/zl3073x.rst Parameters · line 26
Quoted 7 lines
Documentation/networking/devlink/zl3073x.rst +4
-0@@ -20,6 +20,10 @@ Parameters - driverinit - Set the clock ID that is used by the driver for registering DPLL devices and pins. + * - ``phase_offset_avg_factor`` + - runtime + - Set the factor for the exponential moving average used by DPLL phase + measurement block. The value has to be in range <0, 15>.
Maybe put the text in the commit message here as well?
Andrew
Ivan Vecera
maintainerQuoted 33 lines · Andrew Lunn
Quoted 32 lines · Ivan Vecera
The DPLL phase measurement block uses an exponential moving average, calculated using the following equation:
2^N - 1 1
curr_avg=prev_avg* --------- +new_val* -----
2^N 2^NWhere
curr_avgis phase offset reported by the firmware to the driver,prev_avgis previous averaged value andnew_valis currently measured value for particular reference.New measurements are taken approximately 40 Hz or at the frequency of the reference (whichever is lower).
The driver currently uses the averaging factor N=2 which prioritizes a fast response time to track dynamic changes in the phase. But for applications requiring a very stable and precise reading of the average phase offset, and where rapid changes are not expected, a higher factor would be appropriate.
Add devlink device parameter
phase_offset_avg_factorto allow a user set tune the averaging factor via devlink interface.Tested-by Prathosh Satish <[email protected]>Signed-off-by Ivan Vecera <[email protected]>--- Documentation/networking/devlink/zl3073x.rst | 4 ++ drivers/dpll/zl3073x/core.c | 6 +- drivers/dpll/zl3073x/core.h | 8 ++- drivers/dpll/zl3073x/devlink.c | 67 ++++++++++++++++++++ 4 files changed, 82 insertions(+), 3 deletions(-)
Quoted 14 lines
Documentation/networking/devlink/zl3073x.rst Parameters · line 26
Quoted 12 lines
Documentation/networking/devlink/zl3073x.rst +4
-0@@ -20,6 +20,10 @@ Parameters - driverinit - Set the clock ID that is used by the driver for registering DPLL devices and pins. + * - ``phase_offset_avg_factor`` + - runtime + - Set the factor for the exponential moving average used by DPLL phase + measurement block. The value has to be in range <0, 15>.Maybe put the text in the commit message here as well?
Do you mean to put the equation and details from commit message here? This is pretty long.
Ivan
Quoted 49 lines · Ivan Vecera
Quoted 33 lines · Andrew Lunn
Quoted 32 lines · Ivan Vecera
The DPLL phase measurement block uses an exponential moving average, calculated using the following equation:
2^N - 1 1
curr_avg=prev_avg* --------- +new_val* -----
2^N 2^NWhere
curr_avgis phase offset reported by the firmware to the driver,prev_avgis previous averaged value andnew_valis currently measured value for particular reference.New measurements are taken approximately 40 Hz or at the frequency of the reference (whichever is lower).
The driver currently uses the averaging factor N=2 which prioritizes a fast response time to track dynamic changes in the phase. But for applications requiring a very stable and precise reading of the average phase offset, and where rapid changes are not expected, a higher factor would be appropriate.
Add devlink device parameter
phase_offset_avg_factorto allow a user set tune the averaging factor via devlink interface.Tested-by Prathosh Satish <[email protected]>Signed-off-by Ivan Vecera <[email protected]>--- Documentation/networking/devlink/zl3073x.rst | 4 ++ drivers/dpll/zl3073x/core.c | 6 +- drivers/dpll/zl3073x/core.h | 8 ++- drivers/dpll/zl3073x/devlink.c | 67 ++++++++++++++++++++ 4 files changed, 82 insertions(+), 3 deletions(-)Quoted 14 lines
Documentation/networking/devlink/zl3073x.rst Parameters · line 26
Quoted 12 lines
Documentation/networking/devlink/zl3073x.rst +4
-0@@ -20,6 +20,10 @@ Parameters - driverinit - Set the clock ID that is used by the driver for registering DPLL devices and pins. + * - ``phase_offset_avg_factor`` + - runtime + - Set the factor for the exponential moving average used by DPLL phase + measurement block. The value has to be in range <0, 15>.Maybe put the text in the commit message here as well?
Quoted 2 lines
Do you mean to put the equation and details from commit message here? This is pretty long.
So what if it is long? At the moment, it is hiding in the commit message. It is not easy to find, you effectively need to be a kernel developer to find it. If it is in the documentation of the device, it will be much easier to find and understand what this knob actually does.
Andrew
Ivan Vecera
maintainerQuoted 50 lines · Andrew Lunn
Quoted 49 lines · Ivan Vecera
Quoted 47 lines · Andrew Lunn
Quoted 37 lines · Ivan Vecera
The DPLL phase measurement block uses an exponential moving average, calculated using the following equation:
2^N - 1 1
curr_avg=prev_avg* --------- +new_val* -----
2^N 2^NWhere
curr_avgis phase offset reported by the firmware to the driver,prev_avgis previous averaged value andnew_valis currently measured value for particular reference.New measurements are taken approximately 40 Hz or at the frequency of the reference (whichever is lower).
The driver currently uses the averaging factor N=2 which prioritizes a fast response time to track dynamic changes in the phase. But for applications requiring a very stable and precise reading of the average phase offset, and where rapid changes are not expected, a higher factor would be appropriate.
Add devlink device parameter
phase_offset_avg_factorto allow a user set tune the averaging factor via devlink interface.Tested-by Prathosh Satish <[email protected]>Signed-off-by Ivan Vecera <[email protected]>--- Documentation/networking/devlink/zl3073x.rst | 4 ++ drivers/dpll/zl3073x/core.c | 6 +- drivers/dpll/zl3073x/core.h | 8 ++- drivers/dpll/zl3073x/devlink.c | 67 ++++++++++++++++++++ 4 files changed, 82 insertions(+), 3 deletions(-)Documentation/networking/devlink/zl3073x.rst +0
-0Documentation/networking/devlink/zl3073x.rst Parameters · line 26
Quoted 7 lines
Documentation/networking/devlink/zl3073x.rst +4
-0@@ -20,6 +20,10 @@ Parameters - driverinit - Set the clock ID that is used by the driver for registering DPLL devices and pins. + * - ``phase_offset_avg_factor`` + - runtime + - Set the factor for the exponential moving average used by DPLL phase + measurement block. The value has to be in range <0, 15>.Maybe put the text in the commit message here as well?
Quoted 9 lines
Quoted 2 lines
Do you mean to put the equation and details from commit message here? This is pretty long.
So what if it is long? At the moment, it is hiding in the commit message. It is not easy to find, you effectively need to be a kernel developer to find it. If it is in the documentation of the device, it will be much easier to find and understand what this knob actually does.
Agree. I will describe it in more detail in the documentation.
+ optimization proposed by Vadim.
Thanks for the review.
Ivan