Skip to content
  • Leo Yan's avatar
    75eeaddd
    perf arm-spe: Refactor printing string to buffer · 75eeaddd
    Leo Yan authored
    
    
    When outputs strings to the decoding buffer with function snprintf(),
    SPE decoder needs to detects if any error returns from snprintf() and if
    so needs to directly bail out.  If snprintf() returns success, it needs
    to update buffer pointer and reduce the buffer length so can continue to
    output the next string into the consequent memory space.
    
    This complex logics are spreading in the function arm_spe_pkt_desc() so
    there has many duplicate codes for handling error detecting, increment
    buffer pointer and decrement buffer size.
    
    To avoid the duplicate code, this patch introduces a new helper function
    arm_spe_pkt_out_string() which is used to wrap up the complex logics,
    and it's used by the caller arm_spe_pkt_desc().  This patch moves the
    variable 'blen' as the function's local variable so allows to remove
    the unnecessary braces and improve the readability.
    
    This patch simplifies the return value for arm_spe_pkt_desc(): '0' means
    success and other values mean an error has occurred.  To realize this,
    it relies on arm_spe_pkt_out_string()'s parameter 'err', the 'err' is a
    cumulative value, returns its final value if printing buffer is called
    for one time or multiple times.  Finally, the error is handled in a
    central place, rather than directly bailing out in switch-cases, it
    returns error at the end of arm_spe_pkt_desc().
    
    This patch changes the caller arm_spe_dump() to respect the updated
    return value semantics of arm_spe_pkt_desc().
    
    Suggested-by: default avatarDave Martin <Dave.Martin@arm.com>
    Signed-off-by: default avatarLeo Yan <leo.yan@linaro.org>
    Reviewed-by: default avatarAndre Przywara <andre.przywara@arm.com>
    Reviewed-by: default avatarDave Martin <Dave.Martin@arm.com>
    Acked-by: default avatarWill Deacon <will@kernel.org>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Al Grant <Al.Grant@arm.com>
    Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: James Clark <james.clark@arm.com>
    Cc: Jiri Olsa <jolsa@redhat.com>
    Cc: John Garry <john.garry@huawei.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Wei Li <liwei391@huawei.com>
    Link: https://lore.kernel.org/r/20201119152441.6972-2-leo.yan@linaro.org
    
    
    Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    75eeaddd
    perf arm-spe: Refactor printing string to buffer
    Leo Yan authored
    
    
    When outputs strings to the decoding buffer with function snprintf(),
    SPE decoder needs to detects if any error returns from snprintf() and if
    so needs to directly bail out.  If snprintf() returns success, it needs
    to update buffer pointer and reduce the buffer length so can continue to
    output the next string into the consequent memory space.
    
    This complex logics are spreading in the function arm_spe_pkt_desc() so
    there has many duplicate codes for handling error detecting, increment
    buffer pointer and decrement buffer size.
    
    To avoid the duplicate code, this patch introduces a new helper function
    arm_spe_pkt_out_string() which is used to wrap up the complex logics,
    and it's used by the caller arm_spe_pkt_desc().  This patch moves the
    variable 'blen' as the function's local variable so allows to remove
    the unnecessary braces and improve the readability.
    
    This patch simplifies the return value for arm_spe_pkt_desc(): '0' means
    success and other values mean an error has occurred.  To realize this,
    it relies on arm_spe_pkt_out_string()'s parameter 'err', the 'err' is a
    cumulative value, returns its final value if printing buffer is called
    for one time or multiple times.  Finally, the error is handled in a
    central place, rather than directly bailing out in switch-cases, it
    returns error at the end of arm_spe_pkt_desc().
    
    This patch changes the caller arm_spe_dump() to respect the updated
    return value semantics of arm_spe_pkt_desc().
    
    Suggested-by: default avatarDave Martin <Dave.Martin@arm.com>
    Signed-off-by: default avatarLeo Yan <leo.yan@linaro.org>
    Reviewed-by: default avatarAndre Przywara <andre.przywara@arm.com>
    Reviewed-by: default avatarDave Martin <Dave.Martin@arm.com>
    Acked-by: default avatarWill Deacon <will@kernel.org>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Al Grant <Al.Grant@arm.com>
    Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: James Clark <james.clark@arm.com>
    Cc: Jiri Olsa <jolsa@redhat.com>
    Cc: John Garry <john.garry@huawei.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Wei Li <liwei391@huawei.com>
    Link: https://lore.kernel.org/r/20201119152441.6972-2-leo.yan@linaro.org
    
    
    Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Loading