1 From 376fdba15bcf4b106ba7d62ee350baf21099cfbf Mon Sep 17 00:00:00 2001
2 From: popcornmix <popcornmix@gmail.com>
3 Date: Mon, 12 May 2014 15:12:02 +0100
4 Subject: [PATCH 07/54] vchiq: Avoid high load when blocked and unkillable
7 .../interface/vchiq_arm/vchiq_2835_arm.c | 1 +
8 .../vc04_services/interface/vchiq_arm/vchiq_arm.c | 1 +
9 .../interface/vchiq_arm/vchiq_connected.c | 1 +
10 .../vc04_services/interface/vchiq_arm/vchiq_core.c | 1 +
11 .../interface/vchiq_arm/vchiq_kern_lib.c | 1 +
12 .../interface/vchiq_arm/vchiq_killable.h | 69 ++++++++++++++++++++++
13 .../vc04_services/interface/vchiq_arm/vchiq_util.c | 1 +
14 7 files changed, 75 insertions(+)
15 create mode 100644 drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h
17 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
18 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
20 #include "vchiq_arm.h"
21 #include "vchiq_2835.h"
22 #include "vchiq_connected.h"
23 +#include "vchiq_killable.h"
25 #define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
27 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
28 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
30 #include "vchiq_core.h"
31 #include "vchiq_ioctl.h"
32 #include "vchiq_arm.h"
33 +#include "vchiq_killable.h"
35 #define DEVICE_NAME "vchiq"
37 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
38 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
41 #include "vchiq_connected.h"
42 #include "vchiq_core.h"
43 +#include "vchiq_killable.h"
44 #include <linux/module.h>
45 #include <linux/mutex.h>
47 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
48 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
52 #include "vchiq_core.h"
53 +#include "vchiq_killable.h"
55 #define VCHIQ_SLOT_HANDLER_STACK 8192
57 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
58 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
61 #include "vchiq_core.h"
62 #include "vchiq_arm.h"
63 +#include "vchiq_killable.h"
65 /* ---- Public Variables ------------------------------------------------- */
68 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h
71 + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
73 + * Redistribution and use in source and binary forms, with or without
74 + * modification, are permitted provided that the following conditions
76 + * 1. Redistributions of source code must retain the above copyright
77 + * notice, this list of conditions, and the following disclaimer,
78 + * without modification.
79 + * 2. Redistributions in binary form must reproduce the above copyright
80 + * notice, this list of conditions and the following disclaimer in the
81 + * documentation and/or other materials provided with the distribution.
82 + * 3. The names of the above-listed copyright holders may not be used
83 + * to endorse or promote products derived from this software without
84 + * specific prior written permission.
86 + * ALTERNATIVELY, this software may be distributed under the terms of the
87 + * GNU General Public License ("GPL") version 2, as published by the Free
88 + * Software Foundation.
90 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
91 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
92 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
93 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
94 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
95 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
96 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
97 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
98 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
99 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
100 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
103 +#ifndef VCHIQ_KILLABLE_H
104 +#define VCHIQ_KILLABLE_H
106 +#include <linux/mutex.h>
107 +#include <linux/semaphore.h>
109 +#define SHUTDOWN_SIGS (sigmask(SIGKILL) | sigmask(SIGINT) | sigmask(SIGQUIT))
111 +static inline int __must_check down_interruptible_killable(struct semaphore *sem)
113 + /* Allow interception of killable signals only. We don't want to be interrupted by harmless signals like SIGALRM */
115 + sigset_t blocked, oldset;
116 + siginitsetinv(&blocked, SHUTDOWN_SIGS);
117 + sigprocmask(SIG_SETMASK, &blocked, &oldset);
118 + ret = down_interruptible(sem);
119 + sigprocmask(SIG_SETMASK, &oldset, NULL);
122 +#define down_interruptible down_interruptible_killable
125 +static inline int __must_check mutex_lock_interruptible_killable(struct mutex *lock)
127 + /* Allow interception of killable signals only. We don't want to be interrupted by harmless signals like SIGALRM */
129 + sigset_t blocked, oldset;
130 + siginitsetinv(&blocked, SHUTDOWN_SIGS);
131 + sigprocmask(SIG_SETMASK, &blocked, &oldset);
132 + ret = mutex_lock_interruptible(lock);
133 + sigprocmask(SIG_SETMASK, &oldset, NULL);
136 +#define mutex_lock_interruptible mutex_lock_interruptible_killable
139 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
140 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
144 #include "vchiq_util.h"
145 +#include "vchiq_killable.h"
147 static inline int is_pow2(int i)