msm hotplug: *squashing updates*

ARM: MSM: use SGI0 to wake secondary CPUs
	Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

msm: platsmp-8625: modify pen_release variable to volatile
	Since pen_release is a shared variable between cpus. By marking it
	as volatile, compiler won't cache that variable into registers and
	won't optimize the code which access pen_release variable.

	Signed-off-by: tirupathireddy <tirupath@codeaurora.org>

msm: pm2: Raise SPI interrupt instread of SGI to non boot CPUs
	Once APPS comes out of PC and mpdecision want to bring the non-boot
	cpus to online, first CORE0 raises the SPI interrupt(MPCORE) to bring
	the cores(1/2/3) online. While bringing the cores online, CORE0 raises
	the SPI interrupt instead of SGI. Because once APPS does a PC QGIC
	looses its state and none of the non-boot cpus are not capable of
	receiving the SGI interrupt until cores configure the QGIC PPIs&SGIs
	by themselves.

	Signed-off-by: Murali Nalajala <mnalajal@codeaurora.org>

msm: platsmp-8625: Add cold_boot_done as per_cpu variable
	cold_boot_done is declared as an ordinary variable, and useful for
	single secondary cpu, right now. It will not work in the scenarios
	where we have more than two cores in the system. Usage of per-cpu
	variable will make the code more generic for multi-core environment.

	Signed-off-by: tirupathireddy <tirupath@codeaurora.org>

msm: hotplug/platsmp: Fix cpu invaldation pointer arithmetic
	These functions take two void pointers indicating where to start
	and end the invalidation and cache flush. The pointer arithmetic
	is considering the pen_release pointer as an int pointer so
	adding sizeof(pen_release) is adding 16 bytes to the pointer and
	specifying that as the end. This inadvertently invalidates data
	next to the pen_release variable which could be bad. Fix the
	pointer math to only invalidate or clean the region for the
	pen_release variable.

	Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>

msm: hotplug: Change the pen variable in one place
	Other WFI based hotplug implementations set the pen variable to
	-1 in C code and do the appropriate flushing operations in one
	location. They also don't try to invalidate the cache on a
	spurious wakeup and report how many spurious wakeups there were.
	Let's do the same in our code so that we can remove our
	dependence on the dmac_{inv,flush}_range() functions (which are
	no longer upstream) and easily report spurious wakeups to the
	kernel logs.

	This does delay the time we set the pen back to its default
	value, but that doesn't actually matter because generic ARM
	hotplug code already waits for a completion before continuing.

	Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>

msm: hotplug: remove code related to cpu_killed
	Earlier the completion event cpu_killed was used to synchronize
	notify to hot plug framework that the CPU is dead. But now it is
	replaced with another completion event cpu_died and it is placed
	in the hotplug framework itself. So there is no need for a
	platform to implement a completion event.

	But in msm platform driver the completion event related code
	was not removed with the changes in hotplug framework. This
	patch removes the unused code.

	Signed-off-by: Venkat Devarasetty <vdevaras@codeaurora.org>

msm: hotplug: Block hotplug removal of CPU0
	Hotplug removal of CPU0 is not currently supported. Attempts to
	remove it may result in undefined behaviour. Explicitly block
	any such attempts before other hotplug notifiers get the chance
	to run by setting the notifier priority to INT_MAX.

	Signed-off-by: Matt Wagantall <mattw@codeaurora.org>

ARM: gic: Refactor code for gic_configure_and_raise
	Currently the offset and bit calculation in the function was
	hardcoded for IPC1 interrupt. To support other secondary cores
	we have to refactor the code to calculate the offset and bits
	as per the cpu and interrupt number.

	Signed-off-by: Taniya Das <tdas@codeaurora.org>

msm: platsmp-8625: Use real cpu number
	Don't use 2nd core as hardcoded CPU number in raise_clear_spi() and
	msm8625_release_secondary() APIs. It will not work in the scenarios
	where we have more than two cores in the system. Pass the real
	CPU number as parameter to make the code generic.

	Signed-off-by: tirupathireddy <tirupath@codeaurora.org>

msm: platsmp-8625: cleanup macro names
	All the macros defined for 8625 secondary core indicates dual
	core. Cleanup macros to be more generic to fit for multi core.

	Signed-off-by: Taniya Das <tdas@codeaurora.org>

msm: platsmp-8625: Refactor code for multicore environment
	Generic functions added to make code generic to suit multicore
	environment.

	Signed-off-by: Taniya Das <tdas@codeaurora.org>

Signed-off-by: moddingg33k <moddingg33k@t-online.de>
ARM: GIC: *squashing updates*

Signed-off-by: moddingg33k <moddingg33k@t-online.de>
smp: Add generic smpboot facility

Thomas Gleixner's generic-idle patches:

smp: Add task_struct argument to __cpu_up()
	Preparatory patch to make the idle thread allocation for secondary
	cpus generic.

smp: Add generic smpboot facility
	Start a new file, which will hold SMP and CPU hotplug related generic
	infrastructure.

smp: Provide generic idle thread allocation
	All SMP architectures have magic to fork the idle task and to store it
	for reusage when cpu hotplug is enabled. Provide a generic
	infrastructure for it.
	Create/reinit the idle thread for the cpu which is brought up in the
	generic code and hand the thread pointer to the architecture code via
	__cpu_up().
	Note, that fork_idle() is called via a workqueue, because this
	guarantees that the idle thread does not get a reference to a user
	space VM. This can happen when the boot process did not bring up all
	possible cpus and a later cpu_up() is initiated via the sysfs
	interface. In that case fork_idle() would be called in the context of
	the user space task and take a reference on the user space VM.

arm: Use generic idle thread allocation

smp, idle: Allocate idle thread for each possible cpu during boot
	percpu areas are already allocated during boot for each possible cpu.
	percpu idle threads can be considered as an extension of the percpu areas,
	and allocate them for each possible cpu during boot.

	This will eliminate the need for workqueue based idle thread allocation.
	In future we can move the idle thread area into the percpu area too.

	[ tglx: Moved the loop into smpboot.c and added an error check when
	the init code failed to allocate an idle thread for a cpu which
	should be onlined ]

smpboot, idle: Optimize calls to smp_processor_id() in idle_threads_init()
	While trying to initialize idle threads for all cpus, idle_threads_init()
	calls smp_processor_id() in a loop, which is unnecessary. The intent
	is to initialize idle threads for all non-boot cpus. So just use a variable
	to note the boot cpu and use it in the loop.

kthread: Implement park/unpark facility
	To avoid the full teardown/setup of per cpu kthreads in the case of
	cpu hot(un)plug, provide a facility which allows to put the kthread
	into a park position and unpark it when the cpu comes online again.

smpboot: Provide infrastructure for percpu hotplug threads
	Provide a generic interface for setting up and tearing down percpu
	threads.

	On registration the threads for already online cpus are created and
	started. On deregistration (modules) the threads are stoppped.

	During hotplug operations the threads are created, started, parked and
	unparked. The datastructure for registration provides a pointer to
	percpu storage space and optional setup, cleanup, park, unpark
	functions. These functions are called when the thread state changes.

	Each implementation has to provide a function which is queried and
	returns whether the thread should run and the thread function itself.

	The core code handles all state transitions and avoids duplicated code
	in the call sites.

	[ paulmck: Preemption leak fix ]

hotplug: Fix UP bug in smpboot hotplug code
	Because kernel subsystems need their per-CPU kthreads on UP systems as
	well as on SMP systems, the smpboot hotplug kthread functions must be
	provided in UP builds as well as in SMP builds.  This commit therefore
	adds smpboot.c to UP builds and excludes irrelevant code via #ifdef.

softirq: Use hotplug thread infrastructure

watchdog: Use hotplug thread infrastructure

rcu: Use smp_hotplug_thread facility for RCUs per-CPU kthread
	Bring RCU into the new-age CPU-hotplug fold by modifying RCU's per-CPU
	kthread code to use the new smp_hotplug_thread facility.

	[ tglx: Adapted it to use callbacks and to the simplified rcu yield ]

smpboot: Allow selfparking per cpu threads
	The stop machine threads are still killed when a cpu goes offline. The
	reason is that the thread is used to bring the cpu down, so it can't
	be parked along with the other per cpu threads.

	Allow a per cpu thread to be excluded from automatic parking, so it
	can park itself once it's done

	Add a create callback function as well.

kthread: Prevent unpark race which puts threads on the wrong cpu
	The smpboot threads rely on the park/unpark mechanism which binds per
	cpu threads on a particular core. Though the functionality is racy:

	CPU0	       	 	CPU1  	     	    CPU2
	unpark(T)				    wake_up_process(T)
	  clear(SHOULD_PARK)	T runs
				leave parkme() due to !SHOULD_PARK
	  bind_to(CPU2)		BUG_ON(wrong CPU)

	We cannot let the tasks move themself to the target CPU as one of
	those tasks is actually the migration thread itself, which requires
	that it starts running on the target cpu right away.

	The solution to this problem is to prevent wakeups in park mode which
	are not from unpark(). That way we can guarantee that the association
	of the task to the target cpu is working correctly.

	Add a new task state (TASK_PARKED) which prevents other wakeups and
	use this state explicitly for the unpark wakeup.

	Peter noticed: Also, since the task state is visible to userspace and
	all the parked tasks are still in the PID space, its a good hint in ps
	and friends that these tasks aren't really there for the moment.

	The migration thread has another related issue.

	CPU0	      	     	 CPU1
	Bring up CPU2
	create_thread(T)
	park(T)
	 wait_for_completion()
				 parkme()
				 complete()
	sched_set_stop_task()
				 schedule(TASK_PARKED)

	The sched_set_stop_task() call is issued while the task is on the
	runqueue of CPU1 and that confuses the hell out of the stop_task class
	on that cpu. So we need the same synchronizaion before
	sched_set_stop_task().

kthread_worker: reorganize to prepare for flush_kthread_work() reimplementation
	Make the following two non-functional changes.

	* Separate out insert_kthread_work() from queue_kthread_work().

	* Relocate struct kthread_flush_work and kthread_flush_work_fn()
	  definitions above flush_kthread_work().

	v2: Added lockdep_assert_held() in insert_kthread_work() as suggested
	    by Andy Walls.

	Signed-off-by: Tejun Heo <tj@kernel.org>
	Acked-by: Andy Walls <awalls@md.metrocast.net>

kthread_worker: reimplement flush_kthread_work() to allow freeing the work item being executed
	kthread_worker provides minimalistic workqueue-like interface for
	users which need a dedicated worker thread (e.g. for realtime
	priority).  It has basic queue, flush_work, flush_worker operations
	which mostly match the workqueue counterparts; however, due to the way
	flush_work() is implemented, it has a noticeable difference of not
	allowing work items to be freed while being executed.

	While the current users of kthread_worker are okay with the current
	behavior, the restriction does impede some valid use cases.  Also,
	removing this difference isn't difficult and actually makes the code
	easier to understand.

	This patch reimplements flush_kthread_work() such that it uses a
	flush_work item instead of queue/done sequence numbers.

stop_machine: Store task reference in a separate per cpu variable
	To allow the stopper thread being managed by the smpboot thread
	infrastructure separate out the task storage from the stopper data
	structure.

stop_machine: Use smpboot threads
	Use the smpboot thread infrastructure. Mark the stopper thread
	selfparking and park it after it has finished the take_cpu_down()
	work.

stop_machine: Mark per cpu stopper enabled early
	commit 14e568e78 (stop_machine: Use smpboot threads) introduced the
	following regression:

	Before this commit the stopper enabled bit was set in the online
	notifier.

	CPU0				CPU1
	cpu_up
					cpu online
	hotplug_notifier(ONLINE)
	  stopper(CPU1)->enabled = true;
	...
	stop_machine()

	The conversion to smpboot threads moved the enablement to the wakeup
	path of the parked thread. The majority of users seem to have the
	following working order:

	CPU0				CPU1
	cpu_up
					cpu online
	unpark_threads()
	  wakeup(stopper[CPU1])
	....
					stopper thread runs
					  stopper(CPU1)->enabled = true;
	stop_machine()

	But Konrad and Sander have observed:

	CPU0				CPU1
	cpu_up
					cpu online
	unpark_threads()
	  wakeup(stopper[CPU1])
	....
	stop_machine()
					stopper thread runs
					  stopper(CPU1)->enabled = true;

	Now the stop machinery kicks CPU0 into the stop loop, where it gets
	stuck forever because the queue code saw stopper(CPU1)->enabled ==
	false, so CPU0 waits for CPU1 to enter stomp_machine, but the CPU1
	stopper work got discarded due to enabled == false.

	Add a pre_unpark function to the smpboot thread descriptor and call it
	before waking the thread.

	This fixes the problem at hand, but the stop_machine code should be
	more robust. The stopper->enabled flag smells fishy at best.

	Thanks to Konrad for going through a loop of debug patches and
	providing the information to decode this issue.

Signed-off-by: moddingg33k <moddingg33k@t-online.de>
msm: rq_stats: *squashing updates*

msm: rq_stats: Support to know cpu utilization in userspace

	Support to read utilization stats from userspace, used by
	mpdecision. This implementation is independent of governor
	and sampling rates.

	Change-Id: I678c7462ba77d84ce4c51c36a61da7ac99ffecc8
	Signed-off-by: Narayanan Gopalakrishnan <nargop@codeaurora.org>

msm: rq_stats: Fix missing initalization of cur_freq

	Initialize cur_freq variable of each online cpu to the current
	running cpu clock frequency. This avoids zeroing out the load
	calculations until the first notification of the change in CPU
	frequency comes in after CPUFREQ governors are intialized.

	Also when a non boot cpu is up, update its cur_freq variable.

	Change-Id: I950686deff02e2339eefae7d09392dda2174a545
	CRs-fixed: 446017
	Signed-off-by: Venkat Devarasetty <vdevaras@codeaurora.org>

msm:rq_stats: Add hotplug disable attribute

	Register for suspend and resume notifications from kernel. This should
	be done as part of core_initcall so as to receive notification as close
	as possible to the actual event. Add hotplug_disable attribute to
	rq-stats node. Set/clear this attribute based on the suspend/resume events.

	CRS-fixed: 452456
	Change-Id: I76fee349b57f47df40785e9c2503e2e1cc6e064e
	Signed-off-by: Archana Sathyakumar <asathyak@codeaurora.org>

msm:rq_stats: Fix hotplug attribute during the suspend failure

	If the system suspend fails, the hotplug_disable attribute remains
	set. This prevents any change to core status from mpdecision. Reset
	the value of this attribute if the module receives PM_POST_RESTORE
	notification.

	CRS-fixed: 452456
	Change-Id: I22fd639134adbeb8f8f96603e285151480f537ec
	Signed-off-by: Archana Sathyakumar <asathyak@codeaurora.org>

Signed-off-by: moddingg33k <moddingg33k@t-online.de>