Commit fe50c546 authored by Federico Vaga's avatar Federico Vaga

trigger/hrt: fix sysfs value propagation

The HRT trigger has a bug. If you program the fire in the past, the
trigger fires immediately, so ZIO has not the time to propagate the sysfs
value to the current_control. The result is that the acquired block has
the wrong value for attribute exp_{sec|scalar_h}.

The patch introduces a fire delay of 100ms when you program the trigger in the
past. This allows ZIO to propagate the sysfs values.

I am aware that 100ms can be a long time, but it does not matter because
the expected fire should be in the past and it is not possible. Moreover,
the cosistency of the control information will provide information about
the expected fire which is more important than rapidity of a wrong the fire.

---------------------------------------------------------------------
echo 3 > /sys/bus/zio/devices/zzero-0000/zero-input-32/trigger/exp-scalar-h
echo 4 > /sys/bus/zio/devices/zzero-0000/zero-input-32/trigger/exp-scalar-h

[ 1432.799476] zattr_store
[ 1432.799762]  trigger: writing value 3 to sysfs attribute exp-scalar-h
[ 1432.800183] ztt_conf_set:81
[ 1432.800466] ztt_conf_set:146
[ 1432.800846] ztt_fn:167
[ 1432.801162] zio_arm_trigger:131
[ 1432.801162] __zio_arm_input_trigger:82
[ 1432.801162] zbk_alloc_block:94
[ 1432.801162] zio_generic_data_done:135
[ 1432.801162] zbk_store_block:172 (ffff88000d4ebc00, ffff88000d40dd80)
[ 1432.803739] __zattr_propagate_value
[ 1435.736568] zattr_store
[ 1435.737977]  trigger: writing value 4 to sysfs attribute exp-scalar-h
[ 1435.739315] ztt_conf_set:81
[ 1435.740881] ztt_conf_set:146
[ 1435.742389] ztt_fn:167
[ 1435.743381] zio_arm_trigger:131
[ 1435.743381] __zio_arm_input_trigger:82
[ 1435.743381] zbk_alloc_block:94
[ 1435.743381] zio_generic_data_done:135
[ 1435.743381] zbk_store_block:172 (ffff88000d4ebc00, ffff88000d40df40)
[ 1435.747783] __zattr_propagate_value

From zio-dump

block 1 - "Ctrl: trigger-ext-5   0x00000002         2"
block 2 - "Ctrl: trigger-ext-5   0x00000003         3"
---------------------------------------------------------------------
Signed-off-by: 's avatarFederico Vaga <federico.vaga@gmail.com>
parent 765ffa86
......@@ -75,6 +75,7 @@ static int ztt_conf_set(struct device *dev, struct zio_attribute *zattr,
struct zio_ti *ti = to_zio_ti(dev);
struct ztt_instance *ztt = to_ztt_instance(ti);
struct timespec now;
uint64_t now_ns;
ktime_t ktime;
pr_debug("%s:%d\n", __func__, __LINE__);
......@@ -97,12 +98,17 @@ static int ztt_conf_set(struct device *dev, struct zio_attribute *zattr,
ztt->ts.tv_nsec = usr_val;
break;
case ZTT_ATTR_EXP_SEC:
getnstimeofday(&now);
if (usr_val < 10) {
getnstimeofday(&now);
usr_val += now.tv_sec;
}
ztt->ts.tv_sec = usr_val;
ztt->scalar = ztt->ts.tv_sec * NSEC_PER_SEC + ztt->ts.tv_nsec;
if (ztt->ts.tv_sec < now.tv_sec) {
/* Read comment in ZTT_ATTR_EXP_SCALAR_H */
ztt->scalar += 100000000;
}
ktime = timespec_to_ktime(ztt->ts),
ztt->flags |= ZTT_FLAGS_PENDING;
hrtimer_start_range_ns(&ztt->timer, ktime, ztt->slack,
......@@ -117,10 +123,22 @@ static int ztt_conf_set(struct device *dev, struct zio_attribute *zattr,
ztt->scalar_l = usr_val;
break;
case ZTT_ATTR_EXP_SCALAR_H:
getnstimeofday(&now);
now_ns = ktime_to_ns(timespec_to_ktime(now));
ztt->scalar = (uint64_t)usr_val << 32 | ztt->scalar_l;
if (!usr_val) {
getnstimeofday(&now);
ztt->scalar += ktime_to_ns(timespec_to_ktime(now));
/* Use relative time */
ztt->scalar += now_ns;
} else if (ztt->scalar < now_ns) {
/*
* The trigger is programmed in the past. Add a
* delay of 100ms in order to allow the ZIO core
* to propagate the value to the current control.
*
* NOTE: More details in commit message
*/
ztt->scalar = now_ns + 100000000;
}
ktime = ns_to_ktime(ztt->scalar);
ztt->flags |= ZTT_FLAGS_PENDING;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment