From patchwork Thu Nov 29 14:38:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 19 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B9AC760B10 for ; Thu, 29 Nov 2018 15:38:47 +0100 (CET) Received: from avalon.bb.dnainternet.fi (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0D69F55A for ; Thu, 29 Nov 2018 15:38:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1543502327; bh=onzYsWBdh1Lx092lyKm0jvZ1/uyjHBH6xxYAMzLwySQ=; h=From:To:Subject:Date:From; b=Z2JVEezah1EYLXEtJskOyqIRQzgcBySj6co8zlQ7fr3iFwa6worbONmg8x6f1mH4m hoRjBUhrTqG2sW+Rv1UtnXFUxk9TJFjftjMB8YdRIYhCUB2JufHxBj5tl+2B2AckgC N0sAuXgczjDA+srBMUMI1zRHxGKlKxLZKdBJ0dY4= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 29 Nov 2018 16:38:54 +0200 Message-Id: <20181129143854.21311-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] utils: ipu3: Add test process script X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Nov 2018 14:38:47 -0000 The script processes raw frames through the Intel IPU3 IMGU. Signed-off-by: Laurent Pinchart --- I've tested this on an HP Chromebook X2 with v7 of the IPU3 IMGU driver (see https://patchwork.kernel.org/cover/10660325/) and got a kernel oops :-/ [ 136.927788] divide error: 0000 [#1] PREEMPT SMP PTI [ 136.927801] CPU: 2 PID: 2069 Comm: yavta Not tainted 4.20.0-rc1+ #9 [ 136.927806] Hardware name: HP Soraka/Soraka, BIOS 08/30/2018 [ 136.927820] RIP: 0010:ipu3_css_osys_calc+0xc54/0xe14 [ipu3_imgu] [ 136.927825] Code: 89 44 24 28 42 8b 44 86 6c f7 54 24 04 81 64 24 28 00 fd ff ff 81 64 24 04 00 03 00 00 8d 44 03 ff 81 44 24 28 80 03 00 00 99 fb 0f af c3 bb 20 00 00 00 99 f7 fb 8b 5c 24 40 83 fd 01 19 d2 [ 136.927830] RSP: 0018:ffff9af2c0b837c8 EFLAGS: 00010202 [ 136.927835] RAX: 00000000ffffffff RBX: 0000000000000000 RCX: ffff9af2c3e353c0 [ 136.927839] RDX: 00000000ffffffff RSI: ffff9af2c0b838e0 RDI: ffff9af2c3e353c0 [ 136.927843] RBP: 0000000000000001 R08: 0000000000000000 R09: ffff9af2c0b83880 [ 136.927846] R10: ffff9af2c3e353c0 R11: ffff9af2c3e357c0 R12: 00000000000003a0 [ 136.927849] R13: 0000000000025a0a R14: 0000000000000000 R15: 0000000000000000 [ 136.927854] FS: 00007f1eca167700(0000) GS:ffff8c19fab00000(0000) knlGS:0000000000000000 [ 136.927858] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 136.927862] CR2: 00007f1ec776c000 CR3: 00000001312a4003 CR4: 00000000003606e0 [ 136.927865] Call Trace: [ 136.927884] ? __accumulate_pelt_segments+0x29/0x3a [ 136.927892] ? __switch_to_asm+0x40/0x70 [ 136.927899] ? alloc_vmap_area+0x78/0x2f6 [ 136.927903] ? __switch_to_asm+0x40/0x70 [ 136.927907] ? __switch_to_asm+0x34/0x70 [ 136.927911] ? __switch_to_asm+0x40/0x70 [ 136.927915] ? __switch_to_asm+0x34/0x70 [ 136.927923] ? __inc_numa_state+0x28/0x70 [ 136.927929] ? preempt_latency_start+0x1e/0x3d [ 136.927936] ? get_page_from_freelist+0x821/0xb62 [ 136.927943] ? slab_pre_alloc_hook+0x12/0x3b [ 136.927948] ? kmem_cache_alloc_node_trace+0xf6/0x108 [ 136.927954] ? alloc_vmap_area+0x78/0x2f6 [ 136.927965] ipu3_css_cfg_acc+0xa0/0x1b5f [ipu3_imgu] [ 136.927981] ipu3_css_set_parameters+0x286/0x6e7 [ipu3_imgu] [ 136.927995] ipu3_css_start_streaming+0x1230/0x130a [ipu3_imgu] [ 136.928010] imgu_s_stream+0x104/0x2f7 [ipu3_imgu] [ 136.928022] ipu3_vb2_start_streaming+0x168/0x1bd [ipu3_imgu] [ 136.928034] vb2_start_streaming+0x6c/0xf2 [videobuf2_common] [ 136.928044] vb2_core_streamon+0xcf/0x109 [videobuf2_common] [ 136.928061] __video_do_ioctl+0x239/0x388 [videodev] [ 136.928081] video_usercopy+0x25d/0x47a [videodev] [ 136.928097] ? copy_overflow+0x14/0x14 [videodev] [ 136.928115] v4l2_ioctl+0x4d/0x58 [videodev] [ 136.928123] vfs_ioctl+0x1b/0x28 [ 136.928130] do_vfs_ioctl+0x4de/0x566 [ 136.928139] ksys_ioctl+0x50/0x70 [ 136.928146] __x64_sys_ioctl+0x16/0x19 [ 136.928152] do_syscall_64+0x4d/0x5a [ 136.928158] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [ 136.928164] RIP: 0033:0x7f1ec9a84f47 [ 136.928169] Code: 00 00 00 48 8b 05 51 6f 2c 00 64 c7 00 26 00 00 00 48 c7 c0 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 21 6f 2c 00 f7 d8 64 89 01 48 [ 136.928173] RSP: 002b:00007ffe279e6188 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 [ 136.928178] RAX: ffffffffffffffda RBX: 0000000000000007 RCX: 00007f1ec9a84f47 [ 136.928181] RDX: 00007ffe279e6194 RSI: 0000000040045612 RDI: 0000000000000003 [ 136.928184] RBP: 0000000000000000 R08: 00007f1ec776d000 R09: 0000000000000000 [ 136.928188] R10: 0000000000000020 R11: 0000000000000246 R12: 00007ffe279e6360 [ 136.928191] R13: 0000000000000004 R14: 00007ffe279e6360 R15: 00007ffe279e8826 [ 136.928198] Modules linked in: ccm zram arc4 iwlmvm mac80211 intel_rapl x86_pkg_temp_thermal intel_powerclamp coretemp iwlwifi cfg80211 hid_multitouch ipu3_imgu ipu3_cio2 8250_dw videobuf2_dma_sg videobuf2_memops videobuf2_v4l2 processor_thermal_device intel_soc_dts_iosf videobuf2_common ov5670 ov13858 dw9714 v4l2_fwnode v4l2_common videodev media at24 cros_ec_lpcs cros_ec_core int3403_thermal int340x_thermal_zone int3400_thermal acpi_thermal_rel chromeos_pstore mac_hid autofs4 usbhid mmc_block hid_generic i915 sdhci_pci video cqhci i2c_algo_bit sdhci drm_kms_helper syscopyarea sysfillrect sysimgblt fb_sys_fops drm drm_panel_orientation_quirks i2c_hid hid [ 136.928273] ---[ end trace 4ec6c2ce09e06d9d ]--- [ 136.928288] RIP: 0010:ipu3_css_osys_calc+0xc54/0xe14 [ipu3_imgu] [ 136.928293] Code: 89 44 24 28 42 8b 44 86 6c f7 54 24 04 81 64 24 28 00 fd ff ff 81 64 24 04 00 03 00 00 8d 44 03 ff 81 44 24 28 80 03 00 00 99 fb 0f af c3 bb 20 00 00 00 99 f7 fb 8b 5c 24 40 83 fd 01 19 d2 [ 136.928297] RSP: 0018:ffff9af2c0b837c8 EFLAGS: 00010202 [ 136.928302] RAX: 00000000ffffffff RBX: 0000000000000000 RCX: ffff9af2c3e353c0 [ 136.928307] RDX: 00000000ffffffff RSI: ffff9af2c0b838e0 RDI: ffff9af2c3e353c0 [ 136.928311] RBP: 0000000000000001 R08: 0000000000000000 R09: ffff9af2c0b83880 [ 136.928320] R10: ffff9af2c3e353c0 R11: ffff9af2c3e357c0 R12: 00000000000003a0 [ 136.928324] R13: 0000000000025a0a R14: 0000000000000000 R15: 0000000000000000 [ 136.928330] FS: 00007f1eca167700(0000) GS:ffff8c19fab00000(0000) knlGS:0000000000000000 [ 136.928349] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 136.928364] CR2: 00007f1ec776c000 CR3: 00000001312a4003 CR4: 00000000003606e0 utils/ipu3/ipu3-process.sh | 177 +++++++++++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100755 utils/ipu3/ipu3-process.sh diff --git a/utils/ipu3/ipu3-process.sh b/utils/ipu3/ipu3-process.sh new file mode 100755 index 000000000000..6f7526ab1158 --- /dev/null +++ b/utils/ipu3/ipu3-process.sh @@ -0,0 +1,177 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2018, Google Inc. +# +# Author: Laurent Pinchart +# +# ipu3-process.sh - Process raw frames with the Intel IPU3 +# +# The scripts makes use of the following tools, which are expected to be +# executable from the system-wide path or from the local directory: +# +# - media-ctl (from v4l-utils git://linuxtv.org/v4l-utils.git) +# - raw2pnm (from nvt https://github.com/intel/nvt.git) +# - yavta (from git://git.ideasonboard.org/yavta.git) + +# Locate the media device +find_media_device() { + local mdev + + for mdev in /dev/media* ; do + media-ctl -d $mdev -p | grep -q "^driver[ \t]*ipu3-imgu$" && break + mdev= + done + + if [[ -z $mdev ]] ; then + echo "IPU3 media device not found." >&2 + exit 1 + fi + + echo $mdev +} + +# Configure the pipeline +configure_pipeline() { + local enable_3a=1 + local enable_out=1 + local enable_vf=1 + + $mediactl -r + $mediactl -l "\"ipu3-imgu 0 input\":0 -> \"ipu3-imgu 0\":0[1]" + $mediactl -l "\"ipu3-imgu 0\":2 -> \"ipu3-imgu 0 output\":0[$enable_out]" + $mediactl -l "\"ipu3-imgu 0\":3 -> \"ipu3-imgu 0 viewfinder\":0[$enable_vf]" + $mediactl -l "\"ipu3-imgu 0\":4 -> \"ipu3-imgu 0 3a stat\":0[$enable_3a]" +} + +# Perform frame processing through the IMGU +process_frames() { + configure_pipeline + + yavta -n $nbufs -c$frame_count -f $IMGU_OUT_PIXELFORMAT -s $out_size \ + $($mediactl -e "ipu3-imgu 0 output") & + sleep 0.5 + yavta -n $nbufs -c$frame_count -f $IMGU_VF_PIXELFORMAT -s $vf_size \ + $($mediactl -e "ipu3-imgu 0 viewfinder") & + sleep 0.5 + yavta -n $nbufs -c$frame_count \ + $($mediactl -e "ipu3-imgu 0 3a stat") & + sleep 0.5 + yavta -n $nbufs -c$frame_count -f $IMGU_IN_PIXELFORMAT -s $in_size -F$in_file \ + $($mediactl -e "ipu3-imgu 0 input") +} + +# Convert captured files to ppm +convert_files() { + local index=$1 + local type=$2 + local size=$3 + local format=$4 + + local width=$(echo $size | awk -F 'x' '{print $1}') + local height=$(echo $size | awk -F 'x' '{print $2}') + local padded_width=$(expr $(expr $width + 63) / 64 \* 64) + + raw2pnm -x$padded_width -y$height -f$format \ + $output_dir/frames.${type}_$index \ + $output_dir/frames.${type}_$index.ppm +} + +run_test() { + IMGU_IN_PIXELFORMAT=IPU3_SGRBG10 + IMGU_OUT_PIXELFORMAT=NV12 + IMGU_VF_PIXELFORMAT=NV12 + + echo "==== Test ====" + echo "input: $in_file" + echo "output: $IMGU_OUT_PIXELFORMAT/$out_size" + echo "vf: $IMGU_VF_PIXELFORMAT/$vf_size" + + process_frames + + for i in `seq -f '%06.0f' 0 $(($frame_count - 1))`; do + convert_files $i out $out_size $IMGU_OUT_PIXELFORMAT + convert_files $i vf $vf_size $IMGU_VF_PIXELFORMAT + done +} + +validate_size() { + local size=$1 + local width=$(echo $size | awk -F 'x' '{print $1}') + local height=$(echo $size | awk -F 'x' '{print $2}') + + [[ "x${size}" == "x${width}x${height}" ]] +} + +# Print usage message +usage() { + echo "Usage: $(basename $1) [options] " + echo "Supported options:" + echo "--out size output frame size (defaults to input size)" + echo "--vf size viewfinder frame size (defaults to input size)" + echo "" + echo "Where the input file name and size are" + echo "" + echo "input-file = prefix '-' width 'x' height '.' extension" + echo "size = width 'x' height" +} + +# Parse command line arguments +while (( "$#" )) ; do + case $1 in + --out) + out_size=$2 + if ! validate_size $out_size ; then + echo "Invalid size '$out_size'" + usage $0 + exit 1 + fi + shift 2 + ;; + --vf) + vf_size=$2 + if ! validate_size $vf_size ; then + echo "Invalid size '$vf_size'" + usage $0 + exit 1 + fi + shift 2 + ;; + -*) + echo "Unsupported option $1" >&2 + usage $0 + exit 1 + ;; + *) + break + ;; + esac +done + +if [ $# != 1 ] ; then + usage $0 + exit 1 +fi + +in_file=$1 + +# Parse the size from the input file name and perform minimal sanity +# checks. +in_size=$(echo $in_file | sed 's/.*-\([0-9]*\)x\([0-9]*\)\.[a-z0-9]*$/\1x\2/') +validate_size $in_size +if [[ $? != 0 ]] ; then + echo "Invalid input file name $in_file" >&2 + usage $0 + exit 1 +fi + +out_size=${out_size:-$in_size} +vf_size=${vf_size:-$in_size} + +mdev=$(find_media_device) +mediactl="media-ctl -d $mdev" +echo "Using device $mdev" + +output_dir="/tmp" +frame_count=5 +nbufs=7 +run_test