workqueue: consider work function when searching for busy work items

To avoid executing the same work item concurrenlty, workqueue hashes
currently busy workers according to their current work items and looks
up the the table when it wants to execute a new work item.  If there
already is a worker which is executing the new work item, the new item
is queued to the found worker so that it gets executed only after the
current execution finishes.

Unfortunately, a work item may be freed while being executed and thus
recycled for different purposes.  If it gets recycled for a different
work item and queued while the previous execution is still in
progress, workqueue may make the new work item wait for the old one
although the two aren't really related in any way.

In extreme cases, this false dependency may lead to deadlock although
it's extremely unlikely given that there aren't too many self-freeing
work item users and they usually don't wait for other work items.

To alleviate the problem, record the current work function in each
busy worker and match it together with the work item address in
find_worker_executing_work().  While this isn't complete, it ensures
that unrelated work items don't interact with each other and in the
very unlikely case where a twisted wq user triggers it, it's always
onto itself making the culprit easy to spot.

Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Andrey Isakov <andy51@gmx.ru>
Signed-off-by: neobuddy89 <neobuddy89@gmail.com>
lib: Proportions with flexible period

Implement code computing proportions of events of different type (like code in
lib/proportions.c) but allowing periods to have different lengths. This allows
us to have aging periods of fixed wallclock time which gives better proportion
estimates given the hugely varying throughput of different devices - previous
measuring of aging period by number of events has the problem that a reasonable
period length for a system with low-end USB stick is not a reasonable period
length for a system with high-end storage array resulting either in too slow
proportion updates or too fluctuating proportion updates.

Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: neobuddy89 <neobuddy89@gmail.com>
lib: Fix possible deadlock in flexible proportion code

When percpu counter function in fprop_new_period() is interrupted by an
interrupt while holding counter lock, it can cause deadlock when the
interrupt wants to take the lock as well. Fix the problem by disabling
interrupts when calling percpu counter functions.

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: neobuddy89 <neobuddy89@gmail.com>
lib/flex_proportions.c: fix corruption of denominator in flexible proportions

When racing with CPU hotplug, percpu_counter_sum() can return negative
values for the number of observed events.

This confuses fprop_new_period(), which uses unsigned type and as a
result number of events is set to big *positive* number.  From that
moment on, things go pear shaped and can result e.g.  in division by
zero as denominator is later truncated to 32-bits.

This bug causes a divide-by-zero oops in bdi_dirty_limit() in Borislav's
3.6.0-rc6 based kernel.

Fix the issue by using a signed type in fprop_new_period().  That makes
us bail out from the function without doing anything (mistakenly)
thinking there are no events to age.  That makes aging somewhat
inaccurate but getting accurate data would be rather hard.

Signed-off-by: Jan Kara <jack@suse.cz>
Reported-by: Borislav Petkov <bp@amd64.org>
Reported-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: neobuddy89 <neobuddy89@gmail.com>
block: Convert BDI proportion calculations to flexible proportions

Convert calculations of proportion of writeback each bdi does to new flexible
proportion code. That allows us to use aging period of fixed wallclock time
which gives better proportion estimates given the hugely varying throughput of
different devices.

Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Luis Cruz <ljc2491@gmail.com>
Signed-off-by: neobuddy89 <neobuddy89@gmail.com>
cpufreq: cpu-boost: Readd missing bits

The cpufreq patch series was somehow out of sync and
incomplete. Readd the unchanged policy update to source cpu
bit and readd the check for a possible corner case in
try_to_wake_up() that was already missing before.

Signed-off-by: neobuddy89 <neobuddy89@gmail.com>
cpufreq: Break out early if freq equals to target_freq

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
Signed-off-by: neobuddy89 <neobuddy89@gmail.com>
iommu: msm: Move location of local iommu halt

During iommu detach we do a local iommu halt to ensure certain
registers are atomically updated. However, the local iommu halt
is taken at a larger scope than needed. Reduce the scope of this
halt. This will help with performance when detaching a context bank
from an iommu that has another context bank in use.

Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
Signed-off-by: neobuddy89 <neobuddy89@gmail.com>
ASoC: qdsp6 : fix DAP params length in adm dolby set params call

During adm set param call for DAP params, send correct buffer length
to dsp, so DAP module doesnt look for parameters after valid length

Signed-off-by: Jitendra Singh Naruka <jnaruk@codeaurora.org>
Signed-off-by: neobuddy89 <neobuddy89@gmail.com>
ASoC: qdsp6v2: Fixed AAC dual-mono param_size

Corrected the calculation of the param_size field
within the asm_aac_dual_mono_mapping_param struct.

Signed-off-by: Kenneth Westfield <kwestfie@codeaurora.org>
Signed-off-by: neobuddy89 <neobuddy89@gmail.com>
ASoC: msm: Fix underrun in LPA driver

Update LPA platform driver to register restart callback.
The implementation of the callback is to issue a pending buffer
written by the application to restart the session when the dequeue
process is stopped due to underrun issue.
The callback is triggered from ALSA core when the framework
detects that the renderer stopped pulling data but the application
is still writing data. It runs in atomic context.

Signed-off-by: Krishnankutty Kolathappilly <kkolat@codeaurora.org>
Signed-off-by: neobuddy89 <neobuddy89@gmail.com>
ASoC: msm add support for meta data mode for lpa driver

Seek to EOS was causing playback to hang for three seconds before
switching to the next clip. This is because the lpa driver works
on period size. Partial buffers are not handled. Add metadata
mode changes to LPA Driver to support partial frames.

Signed-off-by: Krishnankutty Kolathappilly <kkolat@codeaurora.org>
Signed-off-by: neobuddy89 <neobuddy89@gmail.com>
ASoC: msm: Move ocmem enable request from trigger to open

OCMEM mapping needs to be done only once for multiple instances,
we vote and unvote when a lpa session is open and closed to make
above happen. But this voting and enable ocmem call was being
made in msm_compr_trigger, need to move this to msm_compr_open.

Signed-off-by: Krishnankutty Kolathappilly <kkolat@codeaurora.org>
Signed-off-by: neobuddy89 <neobuddy89@gmail.com>
ASoC: msm: qdsp6v2: Initialize local variable output_meta_data

The local variable output_meta_data is not initialized if
prtd->meta_data_mode is false. It can lead unexpected behavior.

Signed-off-by: Kuirong Wang <kuirongw@codeaurora.org>
Signed-off-by: neobuddy89 <neobuddy89@gmail.com>
ALSA: include: Add new ioctl for metadata mode

Add a new ioctl to support metadata mode in lpa driver. This ioctl
allows lpa driver to work in default alsa compliant mode and also
metadata mode.

Signed-off-by: Krishnankutty Kolathappilly <kkolat@codeaurora.org>
Signed-off-by: neobuddy89 <neobuddy89@gmail.com>
ASoC: msm: Handle error scenarios correctly

In cases where workqueue allocation or device tree
parsing failed, we should return from the function
after freeing up all the resources.

Signed-off-by: Phani Kumar Uppalapati <phaniu@codeaurora.org>
Signed-off-by: neobuddy89 <neobuddy89@gmail.com>
build: Use more generic ramdisk path

Signed-off-by: neobuddy89 <neobuddy89@gmail.com>
defconfig: Chaos 11.0 Stable Release

Signed-off-by: neobuddy89 <neobuddy89@gmail.com>