From patchwork Sun Apr 13 07:29:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sanjay Singh Rawat X-Patchwork-Id: 28298 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E40512036A for ; Sun, 13 Apr 2014 07:30:07 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id lj1sf26673713pab.9 for ; Sun, 13 Apr 2014 00:30:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=JZHWpZXWwz0d7jVotrWDHiWSd5Y65Vz/3SbM25FPEB8=; b=CV8QxM4kmXWIHfIWMr3hJ7piGEdDqEhZly0G96DVzrtfav43RlUkveYgW8KjGvZxBM WADbxakMFT/2tG+QVWZWEwMSEEeLAUx9muAZgdrsc7C+Z1mGuRAZu0YVWnzWYxoaPKst wMpAb1WnVhod54giYd6VZQV4z6eBxPn9who2fX2XoT9vE48zvTs1ru3if/kmdEkAyM81 NK4oZa+G3Z4Wi7fAB2irpRGE5YMYxnmHHhsTZsH9k8pk6biHWz5O36haJKdpCkEYtiP+ rcMJHINtcbfADzx27pOuYyAeHzObZ2wZ2n+PLBG+Ubgq5+EEI0LRZyQOYYp8GRN6oVLn IrJw== X-Gm-Message-State: ALoCoQm4BlD+PGhbYyFYDQW/VV7I4N5NLroZlL8cjEiFBDY//oJt7QpkOsaiO0r6pil9iuGmqr72 X-Received: by 10.66.241.8 with SMTP id we8mr19087347pac.16.1397374207107; Sun, 13 Apr 2014 00:30:07 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.109.131 with SMTP id l3ls2270882qgf.40.gmail; Sun, 13 Apr 2014 00:30:07 -0700 (PDT) X-Received: by 10.52.99.168 with SMTP id er8mr95225vdb.26.1397374207011; Sun, 13 Apr 2014 00:30:07 -0700 (PDT) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id mr9si2202640vec.173.2014.04.13.00.30.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 13 Apr 2014 00:30:06 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.177; Received: by mail-vc0-f177.google.com with SMTP id if17so6140108vcb.8 for ; Sun, 13 Apr 2014 00:30:06 -0700 (PDT) X-Received: by 10.220.133.80 with SMTP id e16mr29631028vct.13.1397374206862; Sun, 13 Apr 2014 00:30:06 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp68076vcb; Sun, 13 Apr 2014 00:30:06 -0700 (PDT) X-Received: by 10.66.141.144 with SMTP id ro16mr93141pab.131.1397374206165; Sun, 13 Apr 2014 00:30:06 -0700 (PDT) Received: from mail-pd0-f173.google.com (mail-pd0-f173.google.com [209.85.192.173]) by mx.google.com with ESMTPS id f8si6869532pbc.28.2014.04.13.00.30.05 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 13 Apr 2014 00:30:06 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.192.173 is neither permitted nor denied by best guess record for domain of sanjay.rawat@linaro.org) client-ip=209.85.192.173; Received: by mail-pd0-f173.google.com with SMTP id z10so6939808pdj.32 for ; Sun, 13 Apr 2014 00:30:05 -0700 (PDT) X-Received: by 10.66.141.197 with SMTP id rq5mr37553134pab.64.1397374205702; Sun, 13 Apr 2014 00:30:05 -0700 (PDT) Received: from localhost.localdomain ([106.216.207.194]) by mx.google.com with ESMTPSA id pr4sm26080659pbb.53.2014.04.13.00.30.03 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 13 Apr 2014 00:30:04 -0700 (PDT) From: Sanjay Singh Rawat To: private-pmwg@linaro.org Cc: Sanjay Singh Rawat Subject: [PATCH PMQA] cpuhotplug: add method to check uevents in userspace Date: Sun, 13 Apr 2014 12:59:54 +0530 Message-Id: <1397374194-7612-1-git-send-email-sanjay.rawat@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: sanjay.rawat@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , - This util reads the NETLINK socket to receive messages from the kernel. For both ubuntu and android uevent_reader can be used to receive events. - bug : 1304251 Signed-off-by: Sanjay Singh Rawat --- Test.mk | 7 +++-- cpuhotplug/cpuhotplug_07.sh | 21 ++++--------- utils/Android.mk | 2 +- utils/uevent_reader.c | 69 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 19 deletions(-) create mode 100644 utils/uevent_reader.c diff --git a/Test.mk b/Test.mk index 19d7346..7c2e0e0 100644 --- a/Test.mk +++ b/Test.mk @@ -20,7 +20,7 @@ # Contributors: # Daniel Lezcano (IBM Corporation) # - initial API and implementation -# + SNT=$(wildcard *sanity.sh) TST=$(wildcard *[^(sanity)].sh) LOG=$(TST:.sh=.log) @@ -29,7 +29,10 @@ CC?=gcc SRC=$(wildcard *.c) EXEC=$(SRC:%.c=%) -check: run_tests +check: build_utils run_tests + +build_utils: + gcc ../utils/uevent_reader.c -o ../utils/uevent_reader SANITY_STATUS:= $(shell if test $(SNT) && test -f $(SNT); then \ ./$(SNT); if test "$$?" -eq 0; then echo 0; else \ diff --git a/cpuhotplug/cpuhotplug_07.sh b/cpuhotplug/cpuhotplug_07.sh index d3674d2..eaeba77 100755 --- a/cpuhotplug/cpuhotplug_07.sh +++ b/cpuhotplug/cpuhotplug_07.sh @@ -28,17 +28,6 @@ source ../include/functions.sh TMPFILE=cpuhotplug_07.tmp -waitfor_udevadm() { - while [ 1 ]; do - lsof | grep udevadm | grep 'sock\|netlink' > /dev/null - if [ $? -eq 0 ]; then - return 0 - fi - log_skip "warning: udev monitor not running" - done - return 1 -} - check_notification() { local cpu=$1 local cpuid=${cpu:3} @@ -52,9 +41,9 @@ check_notification() { # damn ! udevadm is buffering the output, we have to use a temp file # to retrieve the output rm -f $TMPFILE - udevadm monitor --kernel --subsystem-match=cpu > $TMPFILE & + ../utils/uevent_reader $TMPFILE & pid=$! - waitfor_udevadm + sleep 1 set_offline $cpu set_online $cpu @@ -62,13 +51,13 @@ check_notification() { # let the time the notification to reach userspace # and buffered in the file sleep 1 - kill $pid + kill -s INT $pid - grep "offline" $TMPFILE | grep -q "/devices/system/cpu/$cpu" + grep "offline@/devices/system/cpu/$cpu" $TMPFILE ret=$? check "offline event was received" "test $ret -eq 0" - grep "online" $TMPFILE | grep -q "/devices/system/cpu/$cpu" + grep "online@/devices/system/cpu/$cpu" $TMPFILE ret=$? check "online event was received" "test $ret -eq 0" diff --git a/utils/Android.mk b/utils/Android.mk index b49fa45..8c9c644 100644 --- a/utils/Android.mk +++ b/utils/Android.mk @@ -14,5 +14,5 @@ define $(module_name)_etc_add_executable include $(BUILD_EXECUTABLE) endef -test_names := cpuburn cpucycle heat_cpu nanosleep +test_names := cpuburn cpucycle heat_cpu nanosleep uevent_reader $(foreach item,$(test_names),$(eval $(call $(module_name)_etc_add_executable, $(item)))) diff --git a/utils/uevent_reader.c b/utils/uevent_reader.c new file mode 100644 index 0000000..afbb426 --- /dev/null +++ b/utils/uevent_reader.c @@ -0,0 +1,69 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +FILE *fp; + +void exit_handler() +{ + fprintf(stdout, "exiting from uevent reader...\n"); + fclose(fp); +} + +int main(int argc, char *argv[]) +{ + struct sockaddr_nl nls; + struct pollfd pfd; + char buf[512]; + + fp = fopen(argv[1], "w+"); + if (fp == NULL) { + fprintf(stderr, "Can't open input file\n"); + exit(1); + } + + signal(SIGINT, exit_handler); + + /* bind to uevent netlink socket */ + memset(&nls, 0, sizeof(struct sockaddr_nl)); + nls.nl_family = AF_NETLINK; + nls.nl_pid = getpid(); + nls.nl_groups = -1; + + pfd.events = POLLIN; + pfd.fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT); + if (pfd.fd == -1) { + perror("error: socket()"); + exit_handler(); + } + + if (bind(pfd.fd, (struct sockaddr *) &nls, + sizeof(struct sockaddr_nl))) { + perror("error : bind()"); + exit_handler(); + } + + while (-1 != poll(&pfd, 1, -1)) { + int i, len = recv(pfd.fd, buf, sizeof(buf), MSG_DONTWAIT); + if (len == -1) { + perror("error : recv()"); + exit_handler(); + } + + i = 0; + while (i < len) { + fprintf(fp, "%s\n", buf+i); + i += strlen(buf+i)+1; + } + } + + return 0; +}