80ccf8348f112b895fc6a88f2fbbfdac5336a32c
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-3.18 / 0011-vchiq-Avoid-high-load-when-blocked-and-unkillable.patch
1 From e0412853d9f9e12fc7d8a3125cc3b4a62d19007d 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 011/114] vchiq: Avoid high load when blocked and unkillable
5
6 vchiq: Include SIGSTOP and SIGCONT in list of signals not-masked by vchiq to allow gdb to work
7 ---
8 .../interface/vchiq_arm/vchiq_2835_arm.c | 1 +
9 .../vc04_services/interface/vchiq_arm/vchiq_arm.c | 1 +
10 .../interface/vchiq_arm/vchiq_connected.c | 1 +
11 .../vc04_services/interface/vchiq_arm/vchiq_core.c | 1 +
12 .../interface/vchiq_arm/vchiq_kern_lib.c | 1 +
13 .../interface/vchiq_arm/vchiq_killable.h | 69 ++++++++++++++++++++++
14 .../vc04_services/interface/vchiq_arm/vchiq_util.c | 1 +
15 7 files changed, 75 insertions(+)
16 create mode 100644 drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h
17
18 diff --git a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
19 index b3bdaa2..7e7b09f 100644
20 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
21 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
22 @@ -56,6 +56,7 @@
23 #include "vchiq_arm.h"
24 #include "vchiq_2835.h"
25 #include "vchiq_connected.h"
26 +#include "vchiq_killable.h"
27
28 #define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
29
30 diff --git a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
31 index 2596818..3e328ab 100644
32 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
33 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
34 @@ -50,6 +50,7 @@
35 #include "vchiq_ioctl.h"
36 #include "vchiq_arm.h"
37 #include "vchiq_debugfs.h"
38 +#include "vchiq_killable.h"
39
40 #define DEVICE_NAME "vchiq"
41
42 diff --git a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
43 index 65f4b52..5efc62f 100644
44 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
45 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
46 @@ -33,6 +33,7 @@
47
48 #include "vchiq_connected.h"
49 #include "vchiq_core.h"
50 +#include "vchiq_killable.h"
51 #include <linux/module.h>
52 #include <linux/mutex.h>
53
54 diff --git a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
55 index f962027..14a4155 100644
56 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
57 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
58 @@ -32,6 +32,7 @@
59 */
60
61 #include "vchiq_core.h"
62 +#include "vchiq_killable.h"
63
64 #define VCHIQ_SLOT_HANDLER_STACK 8192
65
66 diff --git a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
67 index be9735f..5a4182e 100644
68 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
69 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
70 @@ -39,6 +39,7 @@
71
72 #include "vchiq_core.h"
73 #include "vchiq_arm.h"
74 +#include "vchiq_killable.h"
75
76 /* ---- Public Variables ------------------------------------------------- */
77
78 diff --git a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h
79 new file mode 100644
80 index 0000000..335446e
81 --- /dev/null
82 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h
83 @@ -0,0 +1,69 @@
84 +/**
85 + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
86 + *
87 + * Redistribution and use in source and binary forms, with or without
88 + * modification, are permitted provided that the following conditions
89 + * are met:
90 + * 1. Redistributions of source code must retain the above copyright
91 + * notice, this list of conditions, and the following disclaimer,
92 + * without modification.
93 + * 2. Redistributions in binary form must reproduce the above copyright
94 + * notice, this list of conditions and the following disclaimer in the
95 + * documentation and/or other materials provided with the distribution.
96 + * 3. The names of the above-listed copyright holders may not be used
97 + * to endorse or promote products derived from this software without
98 + * specific prior written permission.
99 + *
100 + * ALTERNATIVELY, this software may be distributed under the terms of the
101 + * GNU General Public License ("GPL") version 2, as published by the Free
102 + * Software Foundation.
103 + *
104 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
105 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
106 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
107 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
108 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
109 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
110 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
111 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
112 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
113 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
114 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
115 + */
116 +
117 +#ifndef VCHIQ_KILLABLE_H
118 +#define VCHIQ_KILLABLE_H
119 +
120 +#include <linux/mutex.h>
121 +#include <linux/semaphore.h>
122 +
123 +#define SHUTDOWN_SIGS (sigmask(SIGKILL) | sigmask(SIGINT) | sigmask(SIGQUIT) | sigmask(SIGTRAP) | sigmask(SIGSTOP) | sigmask(SIGCONT))
124 +
125 +static inline int __must_check down_interruptible_killable(struct semaphore *sem)
126 +{
127 + /* Allow interception of killable signals only. We don't want to be interrupted by harmless signals like SIGALRM */
128 + int ret;
129 + sigset_t blocked, oldset;
130 + siginitsetinv(&blocked, SHUTDOWN_SIGS);
131 + sigprocmask(SIG_SETMASK, &blocked, &oldset);
132 + ret = down_interruptible(sem);
133 + sigprocmask(SIG_SETMASK, &oldset, NULL);
134 + return ret;
135 +}
136 +#define down_interruptible down_interruptible_killable
137 +
138 +
139 +static inline int __must_check mutex_lock_interruptible_killable(struct mutex *lock)
140 +{
141 + /* Allow interception of killable signals only. We don't want to be interrupted by harmless signals like SIGALRM */
142 + int ret;
143 + sigset_t blocked, oldset;
144 + siginitsetinv(&blocked, SHUTDOWN_SIGS);
145 + sigprocmask(SIG_SETMASK, &blocked, &oldset);
146 + ret = mutex_lock_interruptible(lock);
147 + sigprocmask(SIG_SETMASK, &oldset, NULL);
148 + return ret;
149 +}
150 +#define mutex_lock_interruptible mutex_lock_interruptible_killable
151 +
152 +#endif
153 diff --git a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
154 index c2eefef..05e7979 100644
155 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
156 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
157 @@ -32,6 +32,7 @@
158 */
159
160 #include "vchiq_util.h"
161 +#include "vchiq_killable.h"
162
163 static inline int is_pow2(int i)
164 {
165 --
166 1.8.3.2
167