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