f8e9d86e3907f59bd5645848d78b92768b97d08d
[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 --- 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
19 @@ -56,6 +56,7 @@
20  #include "vchiq_arm.h"
21  #include "vchiq_2835.h"
22  #include "vchiq_connected.h"
23 +#include "vchiq_killable.h"
24  
25  #define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
26  
27 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
28 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
29 @@ -49,6 +49,7 @@
30  #include "vchiq_core.h"
31  #include "vchiq_ioctl.h"
32  #include "vchiq_arm.h"
33 +#include "vchiq_killable.h"
34  
35  #define DEVICE_NAME "vchiq"
36  
37 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
38 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
39 @@ -33,6 +33,7 @@
40  
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>
46  
47 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
48 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
49 @@ -32,6 +32,7 @@
50   */
51  
52  #include "vchiq_core.h"
53 +#include "vchiq_killable.h"
54  
55  #define VCHIQ_SLOT_HANDLER_STACK 8192
56  
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
59 @@ -39,6 +39,7 @@
60  
61  #include "vchiq_core.h"
62  #include "vchiq_arm.h"
63 +#include "vchiq_killable.h"
64  
65  /* ---- Public Variables ------------------------------------------------- */
66  
67 --- /dev/null
68 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h
69 @@ -0,0 +1,69 @@
70 +/**
71 + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
72 + *
73 + * Redistribution and use in source and binary forms, with or without
74 + * modification, are permitted provided that the following conditions
75 + * are met:
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.
85 + *
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.
89 + *
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.
101 + */
102 +
103 +#ifndef VCHIQ_KILLABLE_H
104 +#define VCHIQ_KILLABLE_H
105 +
106 +#include <linux/mutex.h>
107 +#include <linux/semaphore.h>
108 +
109 +#define SHUTDOWN_SIGS   (sigmask(SIGKILL) | sigmask(SIGINT) | sigmask(SIGQUIT))
110 +
111 +static inline int __must_check down_interruptible_killable(struct semaphore *sem)
112 +{
113 +       /* Allow interception of killable signals only. We don't want to be interrupted by harmless signals like SIGALRM */
114 +       int ret;
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);
120 +       return ret;
121 +}
122 +#define down_interruptible down_interruptible_killable
123 +
124 +
125 +static inline int __must_check mutex_lock_interruptible_killable(struct mutex *lock)
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 = mutex_lock_interruptible(lock);
133 +       sigprocmask(SIG_SETMASK, &oldset, NULL);
134 +       return ret;
135 +}
136 +#define mutex_lock_interruptible mutex_lock_interruptible_killable
137 +
138 +#endif
139 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
140 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
141 @@ -32,6 +32,7 @@
142   */
143  
144  #include "vchiq_util.h"
145 +#include "vchiq_killable.h"
146  
147  static inline int is_pow2(int i)
148  {