From patchwork Sat Jun 3 14:42:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 101323 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp203943qgd; Sat, 3 Jun 2017 07:44:12 -0700 (PDT) X-Received: by 10.98.36.72 with SMTP id r69mr5974671pfj.86.1496501052597; Sat, 03 Jun 2017 07:44:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496501052; cv=none; d=google.com; s=arc-20160816; b=KkvjwNGnCJobqvxE5nFUAF7xnWuEPRgASJ/nS1b+iaMP18GTgnNZsg6QyXGATA3Em2 4yuSfNcKIk9U9XjiOvW4qNOiXqWwkrIMIK0+jt6hm/+jSw/f5GY6PwvB+7d8xHnIOwpL Wd+6r4C2qVk4/zne0G0FW2lOsJJ1bARuzlT8hipcqBtzhpaUU+YMlOi7FUGuTHavEhgx dP40LkS4lcY9CpRDd4EwGAOnBfj894QkBso8uEL/6YLq1dLphy7LzQxY2Ox0g6H2t7hX BViSzkP2d92Jmnn619KqONY2VZElay08uKwZjRxVHroWiBqPTGnyQrC6GcH0+ALjlCGX pTmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=vmO16NNrdAHfrRIaH/K9C0eZv2XjMgF8owH3ifLKvME=; b=pUg2c4pbuEiqd+JbUQL/YgVW9Ro7UCmwWk69WkSeJAZhc/EhYS3EnCEvEtKApxjCO6 1xpSihQu6CUXpik4f7UB1WpF9WlOJmpq6VUAhQak98+YDLUskzpNjKWbEgAMEU0cYFoZ QaZN7RHxoCxFeLXWqDXazIAI62AKyARad7q+4DjfYBbmG3XKo9W0hye+nFEMbQ3VBRiu HiMTS7CLVqYCBTGQMa7HUlYcmMZmCcWU8+VJo3R/cwyPypiZ3I0COLYEuVPfQSSD+d8/ TExBVurhsc/21YCX1JnfboHUqCMA2+BD/qmUTa9KVr1uMY1PbrPRdQT0dO3Ayq9Ybg0e CXRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c2si2514676plk.369.2017.06.03.07.44.12; Sat, 03 Jun 2017 07:44:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751173AbdFCOnZ (ORCPT + 25 others); Sat, 3 Jun 2017 10:43:25 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:33130 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750765AbdFCOnY (ORCPT ); Sat, 3 Jun 2017 10:43:24 -0400 Received: by mail-pf0-f177.google.com with SMTP id 83so6368054pfr.0 for ; Sat, 03 Jun 2017 07:43:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=vmO16NNrdAHfrRIaH/K9C0eZv2XjMgF8owH3ifLKvME=; b=GnzWgFCGsdOc6GqBr0PKGJAIC5GxceVK8tWjBZu3vjZyA3qulh7RxFX36JxX/Jop1b SgNaB6qrmMy43NhVTREYIq/EzAYUxdqUyi4K3FLJIA6dkxD+Mz8OzjJ/LFJ7nlNflUOM W6CFnuaGrcqLmv9cToeg3Hy//34y/15XpFkB0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=vmO16NNrdAHfrRIaH/K9C0eZv2XjMgF8owH3ifLKvME=; b=NAg08gKjVPN760SJJLqCf7mkVewST3Hn96XG++SxgZQwnkidJN6r9GJLciLOykzkHY agkiv5PNdiKms/xJ8QJBRWKGB4oKwl/zm/vmhFhtxAnoH8hK3KaJGvf9bkkqD+sTZOgl hb38F2YKnQm3pF0Z2GOVv7yN+atDcTLd2UKUtvtF51ekuMFhw+DPak1oInGPj6AlSujO EwibrEOxf9p/hUW5YXN0KqaEvcEB/X0waL1qMFSqgoWoVq9AGTAwS6CKiBKikxtN/MGv 5V/Ec8LDpiLZuV3tOpTOaL4zwW4AZGyTUm9yE8rN0oh1fYa7yiw2iinlPJg84EgNvB1O g0KA== X-Gm-Message-State: AODbwcCtu6u3k/FkGkhbdtmK5ZIlblpiZD374afeeGJBH7H5oE84YmAR lkpRxPa+xiTi91V+ X-Received: by 10.84.231.139 with SMTP id g11mr5391299plk.71.1496501003177; Sat, 03 Jun 2017 07:43:23 -0700 (PDT) Received: from localhost.localdomain (li1568-49.members.linode.com. [139.162.88.49]) by smtp.gmail.com with ESMTPSA id s68sm43510861pgc.5.2017.06.03.07.43.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 03 Jun 2017 07:43:21 -0700 (PDT) From: Leo Yan To: Mathieu Poirier , Will Deacon , Suzuki K Poulose , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Mike Leach , Chunyan Zhang Cc: Leo Yan Subject: [PATCH v1 0/4] coresight: support panic dump functionality Date: Sat, 3 Jun 2017 22:42:52 +0800 Message-Id: <1496500976-18362-1-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ### Introduction ### Embedded Trace Buffer (ETB) provides on-chip storage of trace data, usually has buffer size from 2KB to 8KB. These data has been used for profiling and this has been well implemented in coresight driver. This patch set is to explore ETB RAM data for postmortem debugging. We could consider ETB RAM data is quite useful for postmortem debugging, especially if the hardware design with local ETB buffer (ARM DDI 0461B) chapter 1.2.7. 'Local ETF', with this kind design every CPU has one dedicated ETB RAM. So it's quite handy that we can use alive CPU to help dump the hang CPU ETB RAM. Then we can quickly get to know what's the exact execution flow before its hang. Due ETB RAM buffer has small size, if all CPUs shared one ETB buffer then the trace data for causing error is easily to be overwritten by other PEs; but even so sometimes we still have chance to go through the trace data to assist debugging panic issues. ### Implementation ### Firstly we need provide a unified APIs for panic dump functionality, so it can be easily extended to enable panic dump for multiple drivers. This is finished by patch 0001, it registers panic notifier, and provide the general APIs {coresight_add_panic_cb|coresight_del_panic_cb} as helper functions so any coresight device can add into dump list or delete itself as needed. Generally all the panic dump specific stuff are related to the sinks devices, so this initial version code it only supports sink devices; and Patch 0002 is to add and remove panic callback for sink devices. Patch 0003 and 0004 are to add panic callback functions for tmc and etb10 drivers; so these two drivers can save specific trace data when panic happens. NOTE: patch 0003 for tmc driver panic callback which has been verified on Hikey board. patch 0004 for etb10 has not been tested due lack hardware in hand. ### Usage ### Below are the example for how to use panic dump functionality on 96boards Hikey, the brief flow is: when the panic happens the ETB panic callback function saves trace data into memory, then relies on kdump to use recovery kernel to save DDR content as kernel core dump file; after we transfer kernel core dump file from board to host PC, use 'crash' tool to extract the coresight ETB trace data; finally we can use python script to generate perf format compatible file and use 'perf' to output the readable execution flow. - Save trace data into memory with kdump on Hikey: ARM64's kdump supports to use the same kernel image both for main kernel and dump-capture kernel; so we can simply to load dump-capture kernel with below command: ./kexec -p vmlinux --dtb=hi6220-hikey.dtb --append="root=/dev/mmcblk0p9 rw maxcpus=1 reset_devices earlycon=pl011,0xf7113000 nohlt initcall_debug console=tty0 console=ttyAMA3,115200 clk_ignore_unused" Enable the coresight path for ETB device: echo 1 > /sys/bus/coresight/devices/f6402000.etf/enable_sink echo 1 > /sys/bus/coresight/devices/f659c000.etm/enable_source echo 1 > /sys/bus/coresight/devices/f659d000.etm/enable_source echo 1 > /sys/bus/coresight/devices/f659e000.etm/enable_source echo 1 > /sys/bus/coresight/devices/f659f000.etm/enable_source echo 1 > /sys/bus/coresight/devices/f65dc000.etm/enable_source echo 1 > /sys/bus/coresight/devices/f65dd000.etm/enable_source echo 1 > /sys/bus/coresight/devices/f65de000.etm/enable_source echo 1 > /sys/bus/coresight/devices/f65df000.etm/enable_source - After kernel panic happens, the kdump launches dump-capture kernel; so we need save kernel's dump file on target: cp /proc/vmcore ./vmcore After we download vmcore file from Hikey board to host PC, we can use 'crash' tool to check coresight dump info and extract trace data: crash vmlinux vmcore crash> log [ 37.559337] coresight f6402000.etf: invoke panic dump... [ 37.565460] coresight-tmc f6402000.etf: Dump ETB buffer 0x2000@0xffff80003b8da180 crash> rd 0xffff80003b8da180 0x2000 -r cs_etb_trace.bin - Use python script perf_cs_dump_wrapper.py to wrap trace data for perf format compatible file and finally use perf to output CPU execution flow: On host PC run python script, please note now this script is not flexbile to support all kinds of coresight topologies, this script still has hard coded info related with coresight specific topology in Hikey: python perf_cs_dump_wrapper.py -i cs_etb_trace.bin -o perf.data On Hikey board: ./perf script -v -F cpu,event,ip,sym,symoff --kallsyms ksymbol -i perf.data -k vmlinux [002] instructions: ffff0000087d1d60 psci_cpu_suspend_enter+0x48 [002] instructions: ffff000008093400 cpu_suspend+0x0 [002] instructions: ffff000008093210 __cpu_suspend_enter+0x0 [002] instructions: ffff000008099970 cpu_do_suspend+0x0 [002] instructions: ffff000008093294 __cpu_suspend_enter+0x84 [002] instructions: ffff000008093428 cpu_suspend+0x28 [002] instructions: ffff00000809342c cpu_suspend+0x2c [002] instructions: ffff0000087d1968 psci_suspend_finisher+0x0 [002] instructions: ffff0000087d1768 psci_cpu_suspend+0x0 [002] instructions: ffff0000087d19f0 __invoke_psci_fn_smc+0x0 Have uploaded related tools into folder: http://people.linaro.org/~leo.yan/debug/coresight_dump/ Changes from RFC: * Follow Mathieu's suggestion, use general framework to support dump functionality. * Changed to use perf to analyse trace data. Leo Yan (4): coresight: support panic dump functionality coresight: add and remove panic callback for sink coresight: tmc: hook panic callback for ETB/ETF coresight: etb10: hook panic callback drivers/hwtracing/coresight/Kconfig | 10 ++ drivers/hwtracing/coresight/Makefile | 1 + drivers/hwtracing/coresight/coresight-etb10.c | 16 +++ drivers/hwtracing/coresight/coresight-panic-dump.c | 130 +++++++++++++++++++++ drivers/hwtracing/coresight/coresight-priv.h | 10 ++ drivers/hwtracing/coresight/coresight-tmc-etf.c | 26 +++++ drivers/hwtracing/coresight/coresight.c | 11 ++ include/linux/coresight.h | 2 + 8 files changed, 206 insertions(+) create mode 100644 drivers/hwtracing/coresight/coresight-panic-dump.c -- 2.7.4