Re: [GIT PULL 00/29] perf/core improvements and fixes

2016-02-03 Thread Ingo Molnar

* Arnaldo Carvalho de Melo  wrote:

> Hi Ingo,
> 
>   Please consider pulling,
> 
> - Arnaldo
> 
> The following changes since commit 8eb22c984eb9eeaed47130f5679acd367af69678:
> 
>   Merge tag 'perf-core-for-mingo-3' of 
> git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core 
> (2016-02-03 11:02:37 +0100)
> 
> are available in the git repository at:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git 
> tags/perf-core-for-mingo
> 
> for you to fetch changes up to b62e8dfcda8cb133c062c0e1207afea2476eb7fd:
> 
>   perf hists browser: Add 'L' hotkey to change percent limit (2016-02-03 
> 12:24:22 -0300)
> 
> 
> perf/core improvements and fixes:
> 
> New features:
> 
> - Add 'L' hotkey to dynamicly set the percent threshold for histogram
>   entries and callchains, i.e. dynamicly do what the --percent-limit
>   command line option to 'top' and 'report' does. (Namhyung Kim)
> 
> Infrastructure:
> 
> - Per hists field and sort lists, that will be used, for instance,
>   in the c2c tool (Jiri Olsa)
> 
> Documentation:
> 
> - Update documentation of --sort and --perf-limit options
>   for 'perf report' (Namhyung Kim)
> 
> Signed-off-by: Arnaldo Carvalho de Melo 
> 
> 
> Arnaldo Carvalho de Melo (1):
>   perf top: Move UI initialization ahead of sort setup
> 
> Jiri Olsa (25):
>   perf hists: Factor output_resort from hists__output_resort
>   perf hists: Introduce perf_evsel__output_resort function
>   perf hists: Add _idx fields into struct perf_hpp_fmt
>   perf hists: Use struct perf_hpp_fmt::idx in perf_hpp__reset_width
>   perf hists: Add 'equal' method to perf_hpp_fmt struct
>   perf hists: Add 'hpp__equal' callback function
>   perf hists: Make hpp setup function generic
>   perf report: Move UI initialization ahead of sort setup
>   perf hists: Allocate output sort field
>   perf hists: Remove perf_hpp__column_(disable|enable)
>   perf hists: Properly release format fields
>   perf hists: Separate sort fields parsing into setup_sort_list function
>   perf hists: Separate output fields parsing into setup_output_list 
> function
>   perf hists: Introduce struct perf_hpp_list
>   perf hists: Introduce perf_hpp_list__init function
>   perf hists: Add perf_hpp_list register helpers
>   perf hists: Pass perf_hpp_list all the way through setup_output_list
>   perf hists: Introduce perf_hpp_list__for_each_format macro
>   perf hists: Introduce perf_hpp_list__for_each_format_safe macro
>   perf hists: Introduce perf_hpp_list__for_each_sort_list macro
>   perf hists: Introduce perf_hpp_list__for_each_sort_list_safe macro
>   perf hists: Add struct perf_hpp_list argument to helper functions
>   perf tools: Add hpp_list into struct hists object
>   perf hists: Introduce hists__for_each_format macro
>   perf hists: Introduce hists__for_each_sort_list macro
> 
> Namhyung Kim (3):
>   perf report: Update documentation of --sort option
>   perf report: Update documention of --percent-limit option
>   perf hists browser: Add 'L' hotkey to change percent limit
> 
>  tools/perf/Documentation/perf-report.txt |  37 +++---
>  tools/perf/builtin-annotate.c|   2 +-
>  tools/perf/builtin-report.c  |  20 +--
>  tools/perf/builtin-top.c |  24 ++--
>  tools/perf/tests/hists_cumulate.c|   2 +-
>  tools/perf/tests/hists_filter.c  |   2 +-
>  tools/perf/tests/hists_output.c  |  10 +-
>  tools/perf/ui/browsers/hists.c   |  63 +-
>  tools/perf/ui/gtk/hists.c|   6 +-
>  tools/perf/ui/hist.c | 170 +
>  tools/perf/ui/stdio/hist.c   |   8 +-
>  tools/perf/util/hist.c   |  47 +--
>  tools/perf/util/hist.h   |  65 +++---
>  tools/perf/util/sort.c   | 205 
> +--
>  14 files changed, 425 insertions(+), 236 deletions(-)

Pulled, thanks a lot Arnaldo!

Ingo


[tip:perf/urgent] perf tools: Fix thread lifetime related segfaut in intel_pt

2016-02-03 Thread tip-bot for Adrian Hunter
Commit-ID:  3a4acda1ecbd290973de08250d7dcdfaf5b2fe0f
Gitweb: http://git.kernel.org/tip/3a4acda1ecbd290973de08250d7dcdfaf5b2fe0f
Author: Adrian Hunter 
AuthorDate: Mon, 1 Feb 2016 03:21:04 +
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 2 Feb 2016 12:51:11 -0300

perf tools: Fix thread lifetime related segfaut in intel_pt

intel_pt_process_auxtrace_info() creates a pt->unknown_thread thread
that eventually needs to be freed by the last thread__put() on it, when
its refcount hits zero, which may happen in
intel_pt_process_auxtrace_info() error handling path and triggers the
following segfault, which would happen as well at intel_pt_free, when
tools using this intel_pt codebase frees up resources:

  # perf record -I -e intel_pt/tsc=1,noretcomp=1/u /bin/ls
  0  a  anaconda-ks.cfg  bin   perf.dataperf.data.old  
perf-f23-bringup.todo
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.217 MB perf.data ]
  #
  # perf script -F event,comm,pid,tid,time,addr,ip,sym,dso,iregs
  Samples for 'instructions:u' event do not have IREGS attribute set. Cannot 
print 'iregs' field.
  intel_pt_synth_events: failed to synthesize 'instructions' event type
  Segmentation fault (core dumped)
  #

The problem is: there's a union in 'struct thread' combines a list_head
and a rb_node. The standard life cycle of a thread is: init rb_node in
the constructor, insert it into machine->threads rbtree using rb_node,
move it to machine->dead_threads using list_head, clean in the last
thread__put: list_del_init(>node).

In the above command, it clean a thread before adding it into list,
causes the above segfault.

Since pt->unknown_thread will never live in an rbtree, initialize its
list node so that when list_del_init() is done on it we don't segfault.

After this patch:

  # perf script -F event,comm,pid,tid,time,addr,ip,sym,dso,iregs
  Samples for 'instructions:u' event do not have IREGS attribute set. Cannot 
print 'iregs' field.
  intel_pt_synth_events: failed to synthesize 'instructions' event type
  0x248 [0x88]: failed to process type: 70
  #

Reported-by: Tong Zhang 
Reported-by: Wang Nan 
Signed-off-by: Adrian Hunter 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Josh Poimboeuf 
Link: 
http://lkml.kernel.org/r/1454296865-19749-1-git-send-email-wangn...@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/intel-pt.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 81a2eb7..05d8158 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -2068,6 +2068,15 @@ int intel_pt_process_auxtrace_info(union perf_event 
*event,
err = -ENOMEM;
goto err_free_queues;
}
+
+   /*
+* Since this thread will not be kept in any rbtree not in a
+* list, initialize its list node so that at thread__put() the
+* current thread lifetime assuption is kept and we don't segfault
+* at list_del_init().
+*/
+   INIT_LIST_HEAD(>unknown_thread->node);
+
err = thread__set_comm(pt->unknown_thread, "unknown", 0);
if (err)
goto err_delete_thread;


[tip:perf/urgent] perf probe: Search both .eh_frame and .debug_frame sections for probe location

2016-02-03 Thread tip-bot for Hemant Kumar
Commit-ID:  270bde1e76f400d81f8d0ab68905a18ee17fa2e8
Gitweb: http://git.kernel.org/tip/270bde1e76f400d81f8d0ab68905a18ee17fa2e8
Author: Hemant Kumar 
AuthorDate: Tue, 2 Feb 2016 20:56:46 +0530
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 2 Feb 2016 13:30:16 -0300

perf probe: Search both .eh_frame and .debug_frame sections for probe location

'perf probe' through debuginfo__find_probes() in util/probe-finder.c
checks for the functions' frame descriptions in either .eh_frame section
of an ELF or the .debug_frame.

The check is based on whether either one of these sections is present.
Depending on distro, toolchain defaults, architetcutre, build flags,
etc., CFI might be found in either .eh_frame and/or .debug_frame.
Sometimes, it may happen that, .eh_frame, even if present, may not be
complete and may miss some descriptions.

Therefore, to be sure, to find the CFI covering an address we will
always have to investigate both if available.

For e.g., in powerpc, this may happen:
  $ gcc -g bin.c -o bin

  $ objdump --dwarf ./bin
  <1><145>: Abbrev Number: 7 (DW_TAG_subprogram)
 <146> DW_AT_external   : 1
 <146> DW_AT_name   : (indirect string, offset: 0x9e): main
 <14a> DW_AT_decl_file  : 1
 <14b> DW_AT_decl_line  : 39
 <14c> DW_AT_prototyped : 1
 <14c> DW_AT_type   : <0x57>
 <150> DW_AT_low_pc : 0x17b8

If the .eh_frame and .debug_frame are checked for the same binary, we
will find that, .eh_frame (although present) doesn't contain a
description for "main" function.

But, .debug_frame has a description:

  00d8 0024  FDE cie= pc=17b8..1838
DW_CFA_advance_loc: 16 to 17c8
DW_CFA_def_cfa_offset: 144
DW_CFA_offset_extended_sf: r65 at cfa+16
  ...

Due to this (since, perf checks whether .eh_frame is present and goes on
searching for that address inside that frame), perf is unable to process
the probes:

  # perf probe -x ./bin main
Failed to get call frame on 0x17b8
Error: Failed to add events.

To avoid this issue, we need to check both the sections (.eh_frame and
.debug_frame), which is done in this patch.

Note that, we can always force everything into both .eh_frame and
.debug_frame by:

  $ gcc bin.c -fasynchronous-unwind-tables  -fno-dwarf2-cfi-asm -g -o bin

Signed-off-by: Hemant Kumar 
Acked-by: Masami Hiramatsu 
Cc: linuxppc-...@lists.ozlabs.org
Cc: Mark Wielaard 
Cc: Naveen N. Rao 
Cc: Srikar Dronamraju 
Link: 
http://lkml.kernel.org/r/1454426806-13974-1-git-send-email-hem...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/probe-finder.c | 62 +-
 tools/perf/util/probe-finder.h |  5 +++-
 2 files changed, 41 insertions(+), 26 deletions(-)

diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 2be10fb..4ce5c5e 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -686,8 +686,9 @@ static int call_probe_finder(Dwarf_Die *sc_die, struct 
probe_finder *pf)
pf->fb_ops = NULL;
 #if _ELFUTILS_PREREQ(0, 142)
} else if (nops == 1 && pf->fb_ops[0].atom == DW_OP_call_frame_cfa &&
-  pf->cfi != NULL) {
-   if (dwarf_cfi_addrframe(pf->cfi, pf->addr, ) != 0 ||
+  (pf->cfi_eh != NULL || pf->cfi_dbg != NULL)) {
+   if ((dwarf_cfi_addrframe(pf->cfi_eh, pf->addr, ) != 0 &&
+(dwarf_cfi_addrframe(pf->cfi_dbg, pf->addr, ) != 0)) 
||
dwarf_frame_cfa(frame, >fb_ops, ) != 0) {
pr_warning("Failed to get call frame on 0x%jx\n",
   (uintmax_t)pf->addr);
@@ -1015,8 +1016,7 @@ static int pubname_search_cb(Dwarf *dbg, Dwarf_Global 
*gl, void *data)
return DWARF_CB_OK;
 }
 
-/* Find probe points from debuginfo */
-static int debuginfo__find_probes(struct debuginfo *dbg,
+static int debuginfo__find_probe_location(struct debuginfo *dbg,
  struct probe_finder *pf)
 {
struct perf_probe_point *pp = >pev->point;
@@ -1025,27 +1025,6 @@ static int debuginfo__find_probes(struct debuginfo *dbg,
Dwarf_Die *diep;
int ret = 0;
 
-#if _ELFUTILS_PREREQ(0, 142)
-   Elf *elf;
-   GElf_Ehdr ehdr;
-   GElf_Shdr shdr;
-
-   /* Get the call frame information from this dwarf */
-   elf = dwarf_getelf(dbg->dbg);
-   if (elf == NULL)
-   return -EINVAL;
-
-   if (gelf_getehdr(elf, ) == NULL)
-   return -EINVAL;
-
-   if (elf_section_by_name(elf, , , ".eh_frame", NULL) &&
-   shdr.sh_type == SHT_PROGBITS) {
-   pf->cfi = dwarf_getcfi_elf(elf);
-   } else {
-   pf->cfi = dwarf_getcfi(dbg->dbg);
-   }
-#endif
-
off = 0;
pf->lcache = intlist__new(NULL);
if (!pf->lcache)
@@ -1108,6 +1087,39 @@ found:
return ret;
 }
 
+/* Find probe points from debuginfo 

[tip:perf/urgent] perf tools: tracepoint_error() can receive e= NULL, robustify it

2016-02-03 Thread tip-bot for Adrian Hunter
Commit-ID:  ec183d22cc284a7a1e17f0341219d8ec8ca070cc
Gitweb: http://git.kernel.org/tip/ec183d22cc284a7a1e17f0341219d8ec8ca070cc
Author: Adrian Hunter 
AuthorDate: Tue, 26 Jan 2016 14:05:20 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 1 Feb 2016 11:51:15 -0300

perf tools: tracepoint_error() can receive e=NULL, robustify it

Fixes segmentation fault using, for instance:

  (gdb) run record -I -e intel_pt/tsc=1,noretcomp=1/u /bin/ls
  Starting program: /home/acme/bin/perf record -I -e 
intel_pt/tsc=1,noretcomp=1/u /bin/ls
  Missing separate debuginfos, use: dnf debuginfo-install 
glibc-2.22-7.fc23.x86_64
  [Thread debugging using libthread_db enabled]
  Using host libthread_db library "/lib64/libthread_db.so.1".

 Program received signal SIGSEGV, Segmentation fault.
  0 x004b9ea5 in tracepoint_error (e=0x0, err=13, sys=0x19b1370 
"sched", name=0x19a5d00 "sched_switch") at util/parse-events.c:410
  (gdb) bt
  #0  0x004b9ea5 in tracepoint_error (e=0x0, err=13, sys=0x19b1370 
"sched", name=0x19a5d00 "sched_switch") at util/parse-events.c:410
  #1  0x004b9fc5 in add_tracepoint (list=0x19a5d20, idx=0x7fffb8c0, 
sys_name=0x19b1370 "sched", evt_name=0x19a5d00 "sched_switch", err=0x0, 
head_config=0x0)
  at util/parse-events.c:433
  #2  0x004ba334 in add_tracepoint_event (list=0x19a5d20, 
idx=0x7fffb8c0, sys_name=0x19b1370 "sched", evt_name=0x19a5d00 
"sched_switch", err=0x0, head_config=0x0)
  at util/parse-events.c:498
  #3  0x004bb699 in parse_events_add_tracepoint (list=0x19a5d20, 
idx=0x7fffb8c0, sys=0x19b1370 "sched", event=0x19a5d00 "sched_switch", 
err=0x0, head_config=0x0)
  at util/parse-events.c:936
  #4  0x004f6eda in parse_events_parse (_data=0x7fffb8b0, 
scanner=0x19a49d0) at util/parse-events.y:391
  #5  0x004bc8e5 in parse_events__scanner (str=0x663ff2 
"sched:sched_switch", data=0x7fffb8b0, start_token=258) at 
util/parse-events.c:1361
  #6  0x004bca57 in parse_events (evlist=0x19a5220, str=0x663ff2 
"sched:sched_switch", err=0x0) at util/parse-events.c:1401
  #7  0x00518d5f in perf_evlist__can_select_event (evlist=0x19a3b90, 
str=0x663ff2 "sched:sched_switch") at util/record.c:253
  #8  0x00553c42 in intel_pt_track_switches (evlist=0x19a3b90) at 
arch/x86/util/intel-pt.c:364
  #9  0x005549d1 in intel_pt_recording_options (itr=0x19a2c40, 
evlist=0x19a3b90, opts=0x8edf68 ) at arch/x86/util/intel-pt.c:664
  #10 0x0051e076 in auxtrace_record__options (itr=0x19a2c40, 
evlist=0x19a3b90, opts=0x8edf68 ) at util/auxtrace.c:539
  #11 0x00433368 in cmd_record (argc=1, argv=0x7fffde60, 
prefix=0x0) at builtin-record.c:1264
  #12 0x0049bec2 in run_builtin (p=0x8fa2a8 , argc=5, 
argv=0x7fffde60) at perf.c:390
  #13 0x0049c12a in handle_internal_command (argc=5, 
argv=0x7fffde60) at perf.c:451
  #14 0x0049c278 in run_argv (argcp=0x7fffdcbc, 
argv=0x7fffdcb0) at perf.c:495
  #15 0x0049c60a in main (argc=5, argv=0x7fffde60) at perf.c:618
(gdb)

Intel PT attempts to find the sched:sched_switch tracepoint but that seg
faults if tracefs is not readable, because the error reporting structure
is null, as errors are not reported when automatically adding
tracepoints.  Fix by checking before using.

Committer note:

This doesn't take place in a kernel that supports
perf_event_attr.context_switch, that is the default way that will be
used for tracking context switches, only in older kernels, like 4.2, in
a machine with Intel PT (e.g. Broadwell) for non-priviledged users.

Further info from a similar patch by Wang:

The error is in tracepoint_error: it assumes the 'e' parameter is valid.

However, there are many situation a parse_event() can be called without
parse_events_error. See result of

  $ grep 'parse_events(.*NULL)' ./tools/perf/ -r'

Signed-off-by: Adrian Hunter 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Jiri Olsa 
Cc: Josh Poimboeuf 
Cc: Tong Zhang 
Cc: Wang Nan 
Cc: sta...@vger.kernel.org # v4.4+
Fixes: 196581717d85 ("perf tools: Enhance parsing events tracepoint error 
output")
Link: 
http://lkml.kernel.org/r/1453809921-24596-2-git-send-email-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/parse-events.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 4f7b0ef..813d9b2 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -399,6 +399,9 @@ static void tracepoint_error(struct parse_events_error *e, 
int err,
 {
char help[BUFSIZ];
 
+   if (!e)
+   return;
+
/*
 * We get error directly from syscall errno ( > 0),
 * or from encoded pointer's error ( < 0).


Re: [GIT PULL 0/3] perf/urgent fixes

2016-02-03 Thread Ingo Molnar

* Arnaldo Carvalho de Melo  wrote:

> Hi Ingo,
> 
>   Please consider pulling,
> 
> - Arnaldo
> 
> The following changes since commit 28fb8a5b6e233fc384fb27f9f91f811b40ba9cf8:
> 
>   Merge tag 'perf-urgent-for-mingo' of 
> git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent 
> (2016-01-30 09:15:49 +0100)
> 
> are available in the git repository at:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git 
> tags/perf-urgent-for-mingo
> 
> for you to fetch changes up to 270bde1e76f400d81f8d0ab68905a18ee17fa2e8:
> 
>   perf probe: Search both .eh_frame and .debug_frame sections for probe 
> location (2016-02-02 13:30:16 -0300)
> 
> 
> perf/urgent fixes:
> 
> - tracepoint_error() can receive e=NULL, robustify it, fixes a problem noticed
>   with a very specific combination: Machine with Intel PT (e.g. Broadwell),
>   kernel with no perf_event_attr.context_switch feature (e.g. 4.2) and 
> unreadable
>   tracefs (for instance !root users), making the fallback from
>   perf_event_attr.context_switch to the sched:sched_switch tracepoint to fail
>   reading its info from tracefs, fix it. (Adrian Hunter)
> 
> - Fix segfault in intel pt, by making it follow the 'struct thread' lifetime 
> cycle
>   checking expectations, noticed for instance, when processing perf.data 
> files with
>   Intel PT data using 'perf script' and when exiting 'perf report' (Adrian 
> Hunter)
> 
> - Fix CFI usage from .eh_frame and .debug_frame, which sometimes requires 
> that we
>   fallback from .eh_frame to .debug_frame in architectures such as PowerPC 
> (Hemant Kumar)
> 
> Signed-off-by: Arnaldo Carvalho de Melo 
> 
> 
> Adrian Hunter (2):
>   perf tools: tracepoint_error() can receive e=NULL, robustify it
>   perf tools: Fix thread lifetime related segfaut in intel_pt
> 
> Hemant Kumar (1):
>   perf probe: Search both .eh_frame and .debug_frame sections for probe 
> location
> 
>  tools/perf/util/intel-pt.c |  9 ++
>  tools/perf/util/parse-events.c |  3 ++
>  tools/perf/util/probe-finder.c | 62 
> +-
>  tools/perf/util/probe-finder.h |  5 +++-
>  4 files changed, 53 insertions(+), 26 deletions(-)

Pulled, thanks a lot Arnaldo!

Ingo


[PATCH] xattr handlers: plug a lock leak in simple_xattr_list

2016-02-03 Thread Andreas Gruenbacher
From: Mateusz Guzik 

The code could leak xattrs->lock on error.

Problem introduced with 786534b92f3ce68f4 "tmpfs: listxattr should
include POSIX ACL xattrs".

Signed-off-by: Mateusz Guzik 
Signed-off-by: Andreas Gruenbacher 
Cc:  # 4.4

---
 fs/xattr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/xattr.c b/fs/xattr.c
index 07d0e47..4861322 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -940,7 +940,7 @@ ssize_t simple_xattr_list(struct inode *inode, struct 
simple_xattrs *xattrs,
bool trusted = capable(CAP_SYS_ADMIN);
struct simple_xattr *xattr;
ssize_t remaining_size = size;
-   int err;
+   int err = 0;
 
 #ifdef CONFIG_FS_POSIX_ACL
if (inode->i_acl) {
@@ -965,11 +965,11 @@ ssize_t simple_xattr_list(struct inode *inode, struct 
simple_xattrs *xattrs,
 
err = xattr_list_one(, _size, xattr->name);
if (err)
-   return err;
+   break;
}
spin_unlock(>lock);
 
-   return size - remaining_size;
+   return err ? err : size - remaining_size;
 }
 
 /*
-- 
2.5.0



[PATCH v2 4/4] Documentation: atmel-pmc: add DT bindings for fast startup

2016-02-03 Thread Wenyou Yang
Add DT bindings to configurate the PMC_FSMR and PMC_FSPR registers
to trigger a fast restart signal to PMC.

Signed-off-by: Wenyou Yang 
---

Changes in v2:
 - change the property name and property description.

 .../devicetree/bindings/arm/atmel-pmc.txt  |   63 
 1 file changed, 63 insertions(+)

diff --git a/Documentation/devicetree/bindings/arm/atmel-pmc.txt 
b/Documentation/devicetree/bindings/arm/atmel-pmc.txt
index 795cc78..1b3833b 100644
--- a/Documentation/devicetree/bindings/arm/atmel-pmc.txt
+++ b/Documentation/devicetree/bindings/arm/atmel-pmc.txt
@@ -12,3 +12,66 @@ Examples:
compatible = "atmel,at91rm9200-pmc";
reg = <0xfc00 0x100>;
};
+
+PMC Fast Startup Signals
+
+The PMC Fast Start Signals are used as the wake up source to trigger the PMC
+to wake up the system from the ULP1 mode.
+
+required properties:
+- compatible: Should be "atmel,sama5d2-pmc-fast-startup".
+
+optional properties:
+- atmel,wkup-trigger: boolean, WKUP input can trigger a fast restart signal.
+- atmel,secumod-trigger: boolean, SECUMOD can trigger a fast restart signal.
+- atmel,piobu0-trigger: boolean, PIOBU0 input can trigger a fast restart 
signal.
+- atmel,piobu1-trigger: boolean, PIOBU1 input can trigger a fast restart 
signal.
+- atmel,piobu2-trigger: boolean, PIOBU2 input can trigger a fast restart 
signal.
+- atmel,piobu3-trigger: boolean, PIOBU3 input can trigger a fast restart 
signal.
+- atmel,piobu4-trigger: boolean, PIOBU4 input can trigger a fast restart 
signal.
+- atmel,piobu5-trigger: boolean, PIOBU5 input can trigger a fast restart 
signal.
+- atmel,piobu6-trigger: boolean, PIOBU6 input can trigger a fast restart 
signal.
+- atmel,piobu7-trigger: boolean, PIOBU7 input can trigger a fast restart 
signal.
+- atmel,gmac-wol-trigger: boolean, GMAC_WOL can trigger a fast restart signal.
+- atmel,rtc-alarm-trigger: boolean, RTC alarm can trigger a fast restart 
signal.
+- atmel,usb-resume-trigger: boolean, USB resume can trigger a fast restart
+  signal.
+- atmel,sdmmc-cd-trigger: boolean, SDMMC card detect can trigger a fast
+  restart signal.
+- atmel,rxlp-match-trigger: boolean, Matching condition on RXLP can trigger
+  a fast restart signal.
+- atmel,acc-comparison-trigger: boolean, ACC comparison can trigger a fast
+  restart signal.
+
+- atmel,wkup-trigger-level: string, defines the active polarity of the wake-up
+  input. Supported values are: "high" or "low".
+- atmel,piobu0-trigger-level: string, defines the active polarity of
+  the corresponding PIOBU0 input. Supported values are: "high" or "low".
+- atmel,piobu1-trigger-level: string, defines the active polarity of
+  the corresponding PIOBU1 input. Supported values are: "high" or "low".
+- atmel,piobu2-trigger-level: string, defines the active polarity of
+  the corresponding PIOBU2 input. Supported values are: "high" or "low".
+- atmel,piobu3-trigger-level: string, defines the active polarity of
+  the corresponding PIOBU3 input. Supported values are: "high" or "low".
+- atmel,piobu4-trigger-level: string, defines the active polarity of
+  the corresponding PIOBU4 input. Supported values are: "high" or "low".
+- atmel,piobu5-trigger-level: string, defines the active polarity of
+  the corresponding PIOBU5 input. Supported values are: "high" or "low".
+- atmel,piobu6-trigger-level: string, defines the active polarity of
+  the corresponding PIOBU6 input. Supported values are: "high" or "low".
+- atmel,piobu7-trigger-level: string, defines the active polarity of
+  the corresponding PIOBU7 input. Supported values are: "high" or "low".
+
+Example:
+
+   pmc: pmc@f0014000 {
+   compatible = "atmel,sama5d2-pmc";
+   reg = <0xf0014000 0x160>;
+
+   pmc_fast_restart {
+   compatible = "atmel,sama5d2-pmc-fast-startup";
+   atmel,wkup-trigger;
+   atmel,rtc-alarm-trigger;
+   atmel,wkup-trigger-level = "low";
+   };
+   };
-- 
1.7.9.5



[PATCH v2 3/4] ARM: at91: pm: configure PMC fast startup signals

2016-02-03 Thread Wenyou Yang
The fast startup signal is used as wake up sources for ULP1 mode.
As soon as a fast startup signal is asserted, the embedded 12 MHz
RC oscillator restarts automatically.

This patch is to configure the fast startup signals, which signal
is enabled to trigger the PMC to wake up the system from ULP1 mode
should be configured via the DT.

Signed-off-by: Wenyou Yang 
---

Changes in v2:
 - shorten the pmc-fast-startup property's name.
 - use the value property, instead of bool property for high
   or low triggered.

 arch/arm/mach-at91/pm.c  |  115 ++
 include/linux/clk/at91_pmc.h |   32 
 2 files changed, 147 insertions(+)

diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c
index a7aec35..6763de8 100644
--- a/arch/arm/mach-at91/pm.c
+++ b/arch/arm/mach-at91/pm.c
@@ -24,6 +24,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include 
 #include 
@@ -425,6 +427,117 @@ static void __init at91_pm_sram_init(void)
_pm_suspend_in_sram, at91_pm_suspend_in_sram_sz);
 }
 
+static int __init at91_pmc_fast_startup_init(void)
+{
+   struct device_node *np;
+   struct regmap *regmap;
+   const char *pm;
+   u32 mode = 0, polarity = 0;
+
+   np = of_find_compatible_node(NULL, NULL,
+"atmel,sama5d2-pmc-fast-startup");
+   if (!np)
+   return -ENODEV;
+
+   regmap = syscon_node_to_regmap(of_get_parent(np));
+   if (IS_ERR(regmap)) {
+   pr_info("AT91: failed to find PMC fast startup\n");
+   return PTR_ERR(regmap);
+   }
+
+   mode |= of_property_read_bool(np, "atmel,wkup-trigger") ?
+   AT91_PMC_FSTT0 : 0;
+   mode |= of_property_read_bool(np, "atmel,secumod-trigger") ?
+   AT91_PMC_FSTT1 : 0;
+   mode |= of_property_read_bool(np, "atmel,piobu0-trigger") ?
+   AT91_PMC_FSTT2 : 0;
+   mode |= of_property_read_bool(np, "atmel,piobu1-trigger") ?
+   AT91_PMC_FSTT3 : 0;
+   mode |= of_property_read_bool(np, "atmel,piobu2-trigger") ?
+   AT91_PMC_FSTT4 : 0;
+   mode |= of_property_read_bool(np, "atmel,piobu3-trigger") ?
+   AT91_PMC_FSTT5 : 0;
+   mode |= of_property_read_bool(np, "atmel,piobu4-trigger") ?
+   AT91_PMC_FSTT6 : 0;
+   mode |= of_property_read_bool(np, "atmel,piobu5-trigger") ?
+   AT91_PMC_FSTT7 : 0;
+   mode |= of_property_read_bool(np, "atmel,piobu6-trigger") ?
+   AT91_PMC_FSTT8 : 0;
+   mode |= of_property_read_bool(np, "atmel,piobu7-trigger") ?
+   AT91_PMC_FSTT9 : 0;
+   mode |= of_property_read_bool(np, "atmel,gmac-wol-trigger") ?
+   AT91_PMC_FSTT10 : 0;
+   mode |= of_property_read_bool(np, "atmel,rtc-alarm-trigger") ?
+   AT91_PMC_RTCAL : 0;
+   mode |= of_property_read_bool(np, "atmel,usb-resume-trigger") ?
+   AT91_PMC_USBAL : 0;
+   mode |= of_property_read_bool(np, "atmel,sdmmc-cd-trigger") ?
+   AT91_PMC_SDMMC_CD : 0;
+   mode |= of_property_read_bool(np, "atmel,rxlp-match-trigger") ?
+   AT91_PMC_RXLP_MCE : 0;
+   mode |= of_property_read_bool(np, "atmel,acc-comparison-trigger") ?
+   AT91_PMC_ACC_CE : 0;
+
+   if (!of_property_read_string(np, "atmel,wkup-trigger-level", )) {
+   if (!strcasecmp(pm, "high"))
+   polarity |= AT91_PMC_FSTP0;
+   }
+
+   if (mode & AT91_PMC_FSTT1)
+   polarity |= AT91_PMC_FSTP1;
+
+   if (!of_property_read_string(np, "atmel,piobu0-trigger-level", )) {
+   if (!strcasecmp(pm, "high"))
+   polarity |= AT91_PMC_FSTP2;
+   }
+
+   if (!of_property_read_string(np, "atmel,piobu1-trigger-level", )) {
+   if (!strcasecmp(pm, "high"))
+   polarity |= AT91_PMC_FSTP3;
+   }
+
+   if (!of_property_read_string(np, "atmel,piobu2-trigger-level", )) {
+   if (!strcasecmp(pm, "high"))
+   polarity |= AT91_PMC_FSTP4;
+   }
+
+   if (!of_property_read_string(np, "atmel,piobu3-trigger-level", )) {
+   if (!strcasecmp(pm, "high"))
+   polarity |= AT91_PMC_FSTP5;
+   }
+
+   if (!of_property_read_string(np, "atmel,piobu4-trigger-level", )) {
+   if (!strcasecmp(pm, "high"))
+   polarity |= AT91_PMC_FSTP6;
+   }
+
+   if (!of_property_read_string(np, "atmel,piobu5-trigger-level", )) {
+   if (!strcasecmp(pm, "high"))
+   polarity |= AT91_PMC_FSTP7;
+   }
+
+   if (!of_property_read_string(np, "atmel,piobu6-trigger-level", )) {
+   if (!strcasecmp(pm, "high"))
+   polarity |= AT91_PMC_FSTP8;
+   }
+
+   if (!of_property_read_string(np, "atmel,piobu7-trigger-level", )) {
+   if 

[PATCH v2 2/4] ARM: at91: pm: add ULP1 mode support

2016-02-03 Thread Wenyou Yang
The ULP1 (Ultra Low-power mode 1) is introduced by SAMA5D2.

In the ULP1 mode, all the clocks are shut off, inclusive the embedded
12MHz RC oscillator, so as to achieve the lowest power consumption
with the system in retention mode and able to resume on the wake up
events. As soon as the wake up event is asserted, the embedded 12MHz
RC oscillator restarts automatically.

Signed-off-by: Wenyou Yang 
---

Changes in v2:
 - fix label pm_exit to ulp_exit.

 arch/arm/mach-at91/pm.c |   16 ++-
 arch/arm/mach-at91/pm.h |7 +++
 arch/arm/mach-at91/pm_suspend.S |   97 +++
 include/linux/clk/at91_pmc.h|4 ++
 4 files changed, 122 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c
index f82df15..a7aec35 100644
--- a/arch/arm/mach-at91/pm.c
+++ b/arch/arm/mach-at91/pm.c
@@ -36,6 +36,11 @@
 #include "generic.h"
 #include "pm.h"
 
+#define ULP0_MODE  0x00
+#define ULP1_MODE  0x11
+
+#define SAMA5D2_PMC_VERSION0x20540
+
 void __iomem *pmc;
 
 /*
@@ -52,6 +57,7 @@ extern void at91_pinctrl_gpio_resume(void);
 static struct {
unsigned long uhp_udp_mask;
int memctrl;
+   u32 ulp_mode;
 } at91_pm_data;
 
 void __iomem *at91_ramc_base[2];
@@ -141,8 +147,11 @@ static void at91_pm_suspend(suspend_state_t state)
 {
unsigned int pm_data = at91_pm_data.memctrl;
 
-   pm_data |= (state == PM_SUSPEND_MEM) ?
-   AT91_PM_MODE(AT91_PM_SLOW_CLOCK) : 0;
+   if (state == PM_SUSPEND_MEM) {
+   pm_data |= AT91_PM_MODE(AT91_PM_SLOW_CLOCK);
+   if (at91_pm_data.ulp_mode == ULP1_MODE)
+   pm_data |= AT91_PM_ULP(AT91_PM_ULP1_MODE);
+   }
 
flush_cache_all();
outer_disable();
@@ -497,4 +506,7 @@ void __init sama5_pm_init(void)
at91_pm_data.uhp_udp_mask = AT91SAM926x_PMC_UHP | AT91SAM926x_PMC_UDP;
at91_pm_data.memctrl = AT91_MEMCTRL_DDRSDR;
at91_pm_init(NULL);
+
+   if (readl(pmc + AT91_PMC_VERSION) >= SAMA5D2_PMC_VERSION)
+   at91_pm_data.ulp_mode = ULP1_MODE;
 }
diff --git a/arch/arm/mach-at91/pm.h b/arch/arm/mach-at91/pm.h
index 3fcf881..2e76745 100644
--- a/arch/arm/mach-at91/pm.h
+++ b/arch/arm/mach-at91/pm.h
@@ -39,4 +39,11 @@ extern void __iomem *at91_ramc_base[];
 
 #defineAT91_PM_SLOW_CLOCK  0x01
 
+#define AT91_PM_ULP_OFFSET 5
+#define AT91_PM_ULP_MASK   0x03
+#define AT91_PM_ULP(x) (((x) & AT91_PM_ULP_MASK) << AT91_PM_ULP_OFFSET)
+
+#define AT91_PM_ULP0_MODE  0x00
+#define AT91_PM_ULP1_MODE  0x01
+
 #endif
diff --git a/arch/arm/mach-at91/pm_suspend.S b/arch/arm/mach-at91/pm_suspend.S
index 5fcffdc..f2a5c4b 100644
--- a/arch/arm/mach-at91/pm_suspend.S
+++ b/arch/arm/mach-at91/pm_suspend.S
@@ -41,6 +41,15 @@ tmp2 .reqr5
.endm
 
 /*
+ * Wait for main oscillator selection is done
+ */
+   .macro wait_moscsels
+1: ldr tmp1, [pmc, #AT91_PMC_SR]
+   tst tmp1, #AT91_PMC_MOSCSELS
+   beq 1b
+   .endm
+
+/*
  * Wait until PLLA has locked.
  */
.macro wait_pllalock
@@ -101,6 +110,10 @@ ENTRY(at91_pm_suspend_in_sram)
and r0, r0, #AT91_PM_MODE_MASK
str r0, .pm_mode
 
+   lsr r0, r3, #AT91_PM_ULP_OFFSET
+   and r0, r0, #AT91_PM_ULP_MASK
+   str r0, .ulp_mode
+
/* Active the self-refresh mode */
mov r0, #SRAMC_SELF_FRESH_ACTIVE
bl  at91_sramc_self_refresh
@@ -131,6 +144,13 @@ ENTRY(at91_pm_suspend_in_sram)
orr tmp1, tmp1, #(1 << 29)  /* bit 29 always set */
str tmp1, [pmc, #AT91_CKGR_PLLAR]
 
+   ldr r0, .ulp_mode
+   tst r0, #AT91_PM_ULP1_MODE
+   beq ulp0_mode
+
+   bl  at91_pm_ulp1_mode
+   b   ulp_exit
+
 ulp0_mode:
bl  at91_pm_ulp0_mode
b   ulp_exit
@@ -326,6 +346,81 @@ ENTRY(at91_pm_ulp0_mode)
mov pc, lr
 ENDPROC(at91_pm_ulp0_mode)
 
+/*
+ * void at91_pm_ulp1_mode(void)
+ */
+ENTRY(at91_pm_ulp1_mode)
+   ldr pmc, .pmc_base
+
+   /* Switch the main clock source to 12-MHz RC oscillator */
+   ldr tmp1, [pmc, #AT91_CKGR_MOR]
+   bic tmp1, tmp1, #AT91_PMC_MOSCSEL
+   bic tmp1, tmp1, #AT91_PMC_KEY_MASK
+   orr tmp1, tmp1, #AT91_PMC_KEY
+   str tmp1, [pmc, #AT91_CKGR_MOR]
+
+   wait_moscsels
+
+   /* Disable the crystal oscillator */
+   ldr tmp1, [pmc, #AT91_CKGR_MOR]
+   bic tmp1, tmp1, #AT91_PMC_MOSCEN
+   bic tmp1, tmp1, #AT91_PMC_KEY_MASK
+   orr tmp1, tmp1, #AT91_PMC_KEY
+   str tmp1, [pmc, #AT91_CKGR_MOR]
+
+   /* Switch the master clock source to main clock */
+   ldr tmp1, [pmc, #AT91_PMC_MCKR]
+   bic tmp1, tmp1, #AT91_PMC_CSS
+   orr tmp1, tmp1, #AT91_PMC_CSS_MAIN
+   str tmp1, [pmc, #AT91_PMC_MCKR]
+
+   wait_mckrdy
+
+   /* Enter the ULP1 

Re: Crashes with 874bbfe600a6 in 3.18.25

2016-02-03 Thread Michal Hocko
On Thu 04-02-16 07:37:23, Michal Hocko wrote:
> On Wed 03-02-16 11:59:01, Tejun Heo wrote:
> > On Wed, Feb 03, 2016 at 05:48:52PM +0100, Michal Hocko wrote:
> [...]
> > > anything and add_timer_on also for WORK_CPU_UNBOUND is really required
> > > then we should at least preserve WORK_CPU_UNBOUND in dwork->cpu so that
> > > __queue_work can actually move on to the local CPU properly and handle
> > > the offline cpu properly.
> > 
> > delayed_work->cpu is determined on queueing time.  Dealing with
> > offlined cpus at execution is completley fine.  There's no need to
> > "preserve" anything.
> 
> I've seen you have posted a fix in the mean time but just for my
> understading. Why the following is not an appropriate fix?
> 
> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> index c579dbab2e36..52bb11cf20d1 100644
> --- a/kernel/workqueue.c
> +++ b/kernel/workqueue.c
> @@ -1459,9 +1459,9 @@ static void __queue_delayed_work(int cpu, struct 
> workqueue_struct *wq,
>  
>   dwork->wq = wq;
>   /* timer isn't guaranteed to run in this cpu, record earlier */
> + dwork->cpu = cpu;
>   if (cpu == WORK_CPU_UNBOUND)
>   cpu = raw_smp_processor_id();
> - dwork->cpu = cpu;
>   timer->expires = jiffies + delay;
>  
>   add_timer_on(timer, cpu);

Ok, so after some more thinking about that, this won't really help for
memory less CPU which would still have NUMA_NO_NODE associated with it
AFAIU. So this is definitely better to be handled at unbound_pwq_by_node
level.
-- 
Michal Hocko
SUSE Labs


[PATCH v2 1/4] ARM: at91: pm: create a separate procedure for the ULP0 mode

2016-02-03 Thread Wenyou Yang
To make the code more legible and prepare to add the ULP1 mode
support in the future, create a separate procedure for the ULP0 mode.

Signed-off-by: Wenyou Yang 
---

Changes in v2: None

 arch/arm/mach-at91/pm_suspend.S |   65 ---
 1 file changed, 40 insertions(+), 25 deletions(-)

diff --git a/arch/arm/mach-at91/pm_suspend.S b/arch/arm/mach-at91/pm_suspend.S
index a25defd..5fcffdc 100644
--- a/arch/arm/mach-at91/pm_suspend.S
+++ b/arch/arm/mach-at91/pm_suspend.S
@@ -107,7 +107,7 @@ ENTRY(at91_pm_suspend_in_sram)
 
ldr r0, .pm_mode
tst r0, #AT91_PM_SLOW_CLOCK
-   beq skip_disable_main_clock
+   beq standby_mode
 
ldr pmc, .pmc_base
 
@@ -131,32 +131,13 @@ ENTRY(at91_pm_suspend_in_sram)
orr tmp1, tmp1, #(1 << 29)  /* bit 29 always set */
str tmp1, [pmc, #AT91_CKGR_PLLAR]
 
-   /* Turn off the main oscillator */
-   ldr tmp1, [pmc, #AT91_CKGR_MOR]
-   bic tmp1, tmp1, #AT91_PMC_MOSCEN
-   orr tmp1, tmp1, #AT91_PMC_KEY
-   str tmp1, [pmc, #AT91_CKGR_MOR]
-
-skip_disable_main_clock:
-   ldr pmc, .pmc_base
-
-   /* Wait for interrupt */
-   at91_cpu_idle
-
-   ldr r0, .pm_mode
-   tst r0, #AT91_PM_SLOW_CLOCK
-   beq skip_enable_main_clock
+ulp0_mode:
+   bl  at91_pm_ulp0_mode
+   b   ulp_exit
 
+ulp_exit:
ldr pmc, .pmc_base
 
-   /* Turn on the main oscillator */
-   ldr tmp1, [pmc, #AT91_CKGR_MOR]
-   orr tmp1, tmp1, #AT91_PMC_MOSCEN
-   orr tmp1, tmp1, #AT91_PMC_KEY
-   str tmp1, [pmc, #AT91_CKGR_MOR]
-
-   wait_moscrdy
-
/* Restore PLLA setting */
ldr tmp1, .saved_pllar
str tmp1, [pmc, #AT91_CKGR_PLLAR]
@@ -177,7 +158,15 @@ skip_disable_main_clock:
 
wait_mckrdy
 
-skip_enable_main_clock:
+   b   pm_exit
+
+standby_mode:
+   ldr pmc, .pmc_base
+
+   /* Wait for interrupt */
+   at91_cpu_idle
+
+pm_exit:
/* Exit the self-refresh mode */
mov r0, #SRAMC_SELF_FRESH_EXIT
bl  at91_sramc_self_refresh
@@ -311,6 +300,32 @@ exit_sramc_sf:
mov pc, lr
 ENDPROC(at91_sramc_self_refresh)
 
+/*
+ * void at91_pm_ulp0_mode(void)
+ */
+ENTRY(at91_pm_ulp0_mode)
+   ldr pmc, .pmc_base
+
+   /* Turn off the crystal oscillator */
+   ldr tmp1, [pmc, #AT91_CKGR_MOR]
+   bic tmp1, tmp1, #AT91_PMC_MOSCEN
+   orr tmp1, tmp1, #AT91_PMC_KEY
+   str tmp1, [pmc, #AT91_CKGR_MOR]
+
+   /* Wait for interrupt */
+   at91_cpu_idle
+
+   /* Turn on the crystal oscillator */
+   ldr tmp1, [pmc, #AT91_CKGR_MOR]
+   orr tmp1, tmp1, #AT91_PMC_MOSCEN
+   orr tmp1, tmp1, #AT91_PMC_KEY
+   str tmp1, [pmc, #AT91_CKGR_MOR]
+
+   wait_moscrdy
+
+   mov pc, lr
+ENDPROC(at91_pm_ulp0_mode)
+
 .pmc_base:
.word 0
 .sramc_base:
-- 
1.7.9.5



[PATCH v2 0/4] ARM: at91: pm: add ULP1 mode support

2016-02-03 Thread Wenyou Yang
The ULP1 (Ultra Low-power mode 1) is introduced by SAMA5D2.

In order to achieve the lowest power consumption, in the ULP1 mode,
all the clocks are shut off, inclusive the embedded 12MHz RC oscillator.

The fast startup signal is used as a wake up source for ULP1 mode.
As soon as the wake up event is asserted, the embedded 12MHz RC
oscillator restarts automatically, which fast startup signal
to trigger the PMC to wake up the system from the ULP1 mode can be
configured via DT.

It is based on the following patch set:

http://lists.infradead.org/pipermail/linux-arm-kernel/2015-December/390954.html

Changes in v2:
 - fix label pm_exit to ulp_exit.
 - shorten the pmc-fast-startup property's name.
 - use the value property, instead of bool property for high
   or low triggered.
 - change the property name and property description.

Wenyou Yang (4):
  ARM: at91: pm: create a separate procedure for the ULP0 mode
  ARM: at91: pm: add ULP1 mode support
  ARM: at91: pm: configure PMC fast startup signals
  Documentation: atmel-pmc: add DT bindings for fast startup

 .../devicetree/bindings/arm/atmel-pmc.txt  |   63 
 arch/arm/mach-at91/pm.c|  131 +++-
 arch/arm/mach-at91/pm.h|7 +
 arch/arm/mach-at91/pm_suspend.S|  158 +---
 include/linux/clk/at91_pmc.h   |   36 +
 5 files changed, 370 insertions(+), 25 deletions(-)

-- 
1.7.9.5



[PATCH] mm/slab: re-implement pfmemalloc support

2016-02-03 Thread Joonsoo Kim
Current implementation of pfmemalloc handling in SLAB has some problems.

1) pfmemalloc_active is set to true when there is just one or more
pfmemalloc slabs in the system, but it is cleared when there is
no pfmemalloc slab in one arbitrary kmem_cache. So, pfmemalloc_active
could be wrongly cleared.

2) Search to partial and free list doesn't happen when non-pfmemalloc
object are not found in cpu cache. Instead, allocating new slab happens
and it is not optimal.

3) Even after sk_memalloc_socks() is disabled, cpu cache would keep
pfmemalloc objects tagged with SLAB_OBJ_PFMEMALLOC. It isn't cleared if
sk_memalloc_socks() is disabled so it could cause problem.

4) If cpu cache is filled with pfmemalloc objects, it would cause slow
down non-pfmemalloc allocation.

To me, current pointer tagging approach looks complex and fragile
so this patch re-implement whole thing instead of fixing problems
one by one.

Design principle for new implementation is that

1) Don't disrupt non-pfmemalloc allocation in fast path even if
sk_memalloc_socks() is enabled. It's more likely case than pfmemalloc
allocation.

2) Ensure that pfmemalloc slab is used only for pfmemalloc allocation.

3) Don't consider performance of pfmemalloc allocation in memory
deficiency state.

As a result, all pfmemalloc alloc/free in memory tight state will
be handled in slow-path. If there is non-pfmemalloc free object,
it will be returned first even for pfmemalloc user in fast-path so that
performance of pfmemalloc user isn't affected in normal case and
pfmemalloc objects will be kept as long as possible.

Signed-off-by: Joonsoo Kim 
---
 mm/slab.c | 285 ++
 1 file changed, 118 insertions(+), 167 deletions(-)

Hello, Mel.

May I ask you to review the patch and test it on your swap over nbd setup
in order to check that it has no regression? For me, it's not easy
to setup this environment.

Thanks.

diff --git a/mm/slab.c b/mm/slab.c
index ff6526e..da5e2c1 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -169,12 +169,6 @@ typedef unsigned short freelist_idx_t;
 #define SLAB_OBJ_MAX_NUM ((1 << sizeof(freelist_idx_t) * BITS_PER_BYTE) - 1)
 
 /*
- * true if a page was allocated from pfmemalloc reserves for network-based
- * swap
- */
-static bool pfmemalloc_active __read_mostly;
-
-/*
  * struct array_cache
  *
  * Purpose:
@@ -195,10 +189,6 @@ struct array_cache {
 * Must have this definition in here for the proper
 * alignment of array_cache. Also simplifies accessing
 * the entries.
-*
-* Entries should not be directly dereferenced as
-* entries belonging to slabs marked pfmemalloc will
-* have the lower bits set SLAB_OBJ_PFMEMALLOC
 */
 };
 
@@ -207,23 +197,6 @@ struct alien_cache {
struct array_cache ac;
 };
 
-#define SLAB_OBJ_PFMEMALLOC1
-static inline bool is_obj_pfmemalloc(void *objp)
-{
-   return (unsigned long)objp & SLAB_OBJ_PFMEMALLOC;
-}
-
-static inline void set_obj_pfmemalloc(void **objp)
-{
-   *objp = (void *)((unsigned long)*objp | SLAB_OBJ_PFMEMALLOC);
-   return;
-}
-
-static inline void clear_obj_pfmemalloc(void **objp)
-{
-   *objp = (void *)((unsigned long)*objp & ~SLAB_OBJ_PFMEMALLOC);
-}
-
 /*
  * Need this for bootstrapping a per node allocator.
  */
@@ -620,120 +593,24 @@ static struct array_cache *alloc_arraycache(int node, 
int entries,
return ac;
 }
 
-static inline bool is_slab_pfmemalloc(struct page *page)
-{
-   return PageSlabPfmemalloc(page);
-}
-
-/* Clears pfmemalloc_active if no slabs have pfmalloc set */
-static void recheck_pfmemalloc_active(struct kmem_cache *cachep,
-   struct array_cache *ac)
-{
-   struct kmem_cache_node *n = get_node(cachep, numa_mem_id());
-   struct page *page;
-   unsigned long flags;
-
-   if (!pfmemalloc_active)
-   return;
-
-   spin_lock_irqsave(>list_lock, flags);
-   list_for_each_entry(page, >slabs_full, lru)
-   if (is_slab_pfmemalloc(page))
-   goto out;
-
-   list_for_each_entry(page, >slabs_partial, lru)
-   if (is_slab_pfmemalloc(page))
-   goto out;
-
-   list_for_each_entry(page, >slabs_free, lru)
-   if (is_slab_pfmemalloc(page))
-   goto out;
-
-   pfmemalloc_active = false;
-out:
-   spin_unlock_irqrestore(>list_lock, flags);
-}
-
-static void *__ac_get_obj(struct kmem_cache *cachep, struct array_cache *ac,
-   gfp_t flags, bool force_refill)
+static noinline void cache_free_pfmemalloc(struct kmem_cache *cachep,
+   void *objp)
 {
-   int i;
-   void *objp = ac->entry[--ac->avail];
-
-   /* Ensure the caller is 

[PATCH v2 0/2] Set the Raspberry Pi Ethernet MAC address

2016-02-03 Thread Lubomir Rintel
Hi,

an updated patch pair addressing the feedback. Originally submitted
in [1]. Still not ready for merge as it needs the usb core [2] change
and an U-Boot change [3] to work properly. 

[1] [PATCH 0/2] Set the Raspberry Pi Ethernet MAC address

http://lists.infradead.org/pipermail/linux-rpi-kernel/2016-February/003207.html

[2] USB: core: let USB device know device node
https://patchwork.ozlabs.org/patch/572621/

[3] [U-Boot] [PATCH] rpi: set ethaddr as well
http://lists.denx.de/pipermail/u-boot/2016-February/244663.html

Regards,
Lubo



[PATCH v2 1/2] ARM: bcm2835: dt: Add the ethernet to the device trees

2016-02-03 Thread Lubomir Rintel
The hub and the ethernet in its port 1 are hardwired on the board.

Compared to the adapters that can be plugged into the USB ports, this
one has no serial EEPROM to store its MAC. Nevertheless, the Raspberry Pi
has the MAC address for this adapter in its ROM, accessible from its
firmware.

U-Boot can read out the address and set the local-mac-address property of the
node with "ethernet" alias. Let's add the node so that U-Boot can do its
business.

Model B rev2 and Model B+ entries were verified by me, the hierarchy and
pid/vid pair for the Version 2 was provided by Olivier Blin. Original
Model B is a blind short, though very likely correct.

Signed-off-by: Lubomir Rintel 
---
Changes since v1:
  - s/@01/@1/ for ethernet and the hub
  - Corrected the vid/pid pairs for hub and ethernet
  - Added Model B rev2 and version 2 board changes
  - Fixed a missing semicolon typo

 arch/arm/boot/dts/bcm2835-rpi-b-plus.dts | 18 ++
 arch/arm/boot/dts/bcm2835-rpi-b-rev2.dts | 18 ++
 arch/arm/boot/dts/bcm2835-rpi-b.dts  | 18 ++
 arch/arm/boot/dts/bcm2836-rpi-2-b.dts| 18 ++
 arch/arm/boot/dts/bcm283x.dtsi   |  4 +++-
 5 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/bcm2835-rpi-b-plus.dts 
b/arch/arm/boot/dts/bcm2835-rpi-b-plus.dts
index ef54050..983353f 100644
--- a/arch/arm/boot/dts/bcm2835-rpi-b-plus.dts
+++ b/arch/arm/boot/dts/bcm2835-rpi-b-plus.dts
@@ -6,6 +6,10 @@
compatible = "raspberrypi,model-b-plus", "brcm,bcm2835";
model = "Raspberry Pi Model B+";
 
+   aliases {
+   ethernet = 
+   };
+
leds {
act {
gpios = < 47 0>;
@@ -29,3 +33,17 @@
brcm,function = ;
};
 };
+
+ {
+   usb1@1 {
+   compatible = "usb0424,9514";
+   reg = <01>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   ethernet: usbether@1 {
+   compatible = "usb0424,ec00";
+   reg = <01>;
+   };
+   };
+};
diff --git a/arch/arm/boot/dts/bcm2835-rpi-b-rev2.dts 
b/arch/arm/boot/dts/bcm2835-rpi-b-rev2.dts
index 86f1f2f..4b695a0 100644
--- a/arch/arm/boot/dts/bcm2835-rpi-b-rev2.dts
+++ b/arch/arm/boot/dts/bcm2835-rpi-b-rev2.dts
@@ -6,6 +6,10 @@
compatible = "raspberrypi,model-b-rev2", "brcm,bcm2835";
model = "Raspberry Pi Model B rev2";
 
+   aliases {
+   ethernet = 
+   };
+
leds {
act {
gpios = < 16 1>;
@@ -22,3 +26,17 @@
brcm,function = ;
};
 };
+
+ {
+   usb1@1 {
+   compatible = "usb0424,9512";
+   reg = <01>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   ethernet: usbether@1 {
+   compatible = "usb0424,ec00";
+   reg = <01>;
+   };
+   };
+};
diff --git a/arch/arm/boot/dts/bcm2835-rpi-b.dts 
b/arch/arm/boot/dts/bcm2835-rpi-b.dts
index 4859e9d..749648e 100644
--- a/arch/arm/boot/dts/bcm2835-rpi-b.dts
+++ b/arch/arm/boot/dts/bcm2835-rpi-b.dts
@@ -6,6 +6,10 @@
compatible = "raspberrypi,model-b", "brcm,bcm2835";
model = "Raspberry Pi Model B";
 
+   aliases {
+   ethernet = 
+   };
+
leds {
act {
gpios = < 16 1>;
@@ -16,3 +20,17 @@
  {
pinctrl-0 = <  >;
 };
+
+ {
+   usb1@1 {
+   compatible = "usb0424,9512";
+   reg = <01>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   ethernet: usbether@1 {
+   compatible = "usb0424,ec00";
+   reg = <01>;
+   };
+   };
+};
diff --git a/arch/arm/boot/dts/bcm2836-rpi-2-b.dts 
b/arch/arm/boot/dts/bcm2836-rpi-2-b.dts
index ff94666..2bc1a96 100644
--- a/arch/arm/boot/dts/bcm2836-rpi-2-b.dts
+++ b/arch/arm/boot/dts/bcm2836-rpi-2-b.dts
@@ -10,6 +10,10 @@
reg = <0 0x4000>;
};
 
+   aliases {
+   ethernet = 
+   };
+
leds {
act {
gpios = < 47 0>;
@@ -33,3 +37,17 @@
brcm,function = ;
};
 };
+
+ {
+   usb1@1 {
+   compatible = "usb0424,9514";
+   reg = <01>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   ethernet: usbether@1 {
+   compatible = "usb0424,ec00";
+   reg = <01>;
+   };
+   };
+};
diff --git a/arch/arm/boot/dts/bcm283x.dtsi b/arch/arm/boot/dts/bcm283x.dtsi
index 971e741..bc5fde1 100644
--- a/arch/arm/boot/dts/bcm283x.dtsi
+++ b/arch/arm/boot/dts/bcm283x.dtsi
@@ -187,10 +187,12 @@
status = "disabled";
};
 
-   usb@7e98 {
+   

[PATCH 2/2] net/smscx5xx: use the device tree for mac address

2016-02-03 Thread Lubomir Rintel
From: Arnd Bergmann 

This takes the MAC address for smsc75xx/smsc95xx USB network devices
from a the device tree. This is required to get a usable persistent
address on the popular beagleboard, whose hardware designers
accidentally forgot that an ethernet device really requires an a
MAC address to be functional.

The Raspberry Pi also ships smsc9514 without a serial EEPROM, stores the MAC
address in ROM accessible via VC4 firmware.

The smsc75xx and smsc95xx drivers are just two copies of the
same code, so better fix both.

[lkund...@v3.sk: updated to use of_get_property() as per suggestion from Arnd,
reworded the message and comments a bit]

Tested-by: Lubomir Rintel 
Signed-off-by: Arnd Bergmann 
---
Changes since v1:
  - Made use of_get_property()
  - Amended comments/commit message a bit

 drivers/net/usb/smsc75xx.c | 12 +++-
 drivers/net/usb/smsc95xx.c | 12 +++-
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c
index 30033db..8266e27 100644
--- a/drivers/net/usb/smsc75xx.c
+++ b/drivers/net/usb/smsc75xx.c
@@ -29,6 +29,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "smsc75xx.h"
 
 #define SMSC_CHIPNAME  "smsc75xx"
@@ -761,6 +762,8 @@ static int smsc75xx_ioctl(struct net_device *netdev, struct 
ifreq *rq, int cmd)
 
 static void smsc75xx_init_mac_address(struct usbnet *dev)
 {
+   const u8 *mac_addr;
+
/* try reading mac address from EEPROM */
if (smsc75xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
dev->net->dev_addr) == 0) {
@@ -772,7 +775,14 @@ static void smsc75xx_init_mac_address(struct usbnet *dev)
}
}
 
-   /* no eeprom, or eeprom values are invalid. generate random MAC */
+   /* maybe the boot loader passed the MAC address in devicetree */
+   mac_addr = of_get_mac_address (dev->udev->dev.of_node);
+   if (mac_addr) {
+   memcpy(dev->net->dev_addr, mac_addr, ETH_ALEN);
+   return;
+   }
+
+   /* no useful static MAC address found. generate a random one */
eth_hw_addr_random(dev->net);
netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");
 }
diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index 66b3ab9..623bb2e 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -29,6 +29,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "smsc95xx.h"
 
 #define SMSC_CHIPNAME  "smsc95xx"
@@ -765,6 +766,8 @@ static int smsc95xx_ioctl(struct net_device *netdev, struct 
ifreq *rq, int cmd)
 
 static void smsc95xx_init_mac_address(struct usbnet *dev)
 {
+   const u8 *mac_addr;
+
/* try reading mac address from EEPROM */
if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
dev->net->dev_addr) == 0) {
@@ -775,7 +778,14 @@ static void smsc95xx_init_mac_address(struct usbnet *dev)
}
}
 
-   /* no eeprom, or eeprom values are invalid. generate random MAC */
+   /* maybe the boot loader passed the MAC address in devicetree */
+   mac_addr = of_get_mac_address (dev->udev->dev.of_node);
+   if (mac_addr) {
+   memcpy(dev->net->dev_addr, mac_addr, ETH_ALEN);
+   return;
+   }
+
+   /* no useful static MAC address found. generate a random one */
eth_hw_addr_random(dev->net);
netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");
 }
-- 
2.5.0



Re: [PATCH 2/2] ARM: bcm2835: dt: Add the ethernet to the device tree

2016-02-03 Thread Lubomir Rintel
On Thu, 2016-02-04 at 06:28 +, Peter Chen wrote:
>  
> > Lubomir Rintel  writes:
> > 
> > > diff --git a/arch/arm/boot/dts/bcm2835-rpi-b-plus.dts
> > > b/arch/arm/boot/dts/bcm2835-rpi-b-plus.dts
> > > index ef54050..32bbd2a 100644
> > > --- a/arch/arm/boot/dts/bcm2835-rpi-b-plus.dts
> > > +++ b/arch/arm/boot/dts/bcm2835-rpi-b-plus.dts
> > 
> > Hi,
> > 
> > Shouldn't this be common to all RPi1 B and RPi2 models, instead of
> > being
> > specific to just RPi B+?
> > 
> > > + {
> > > + usb1@01 {
> > > + compatible = "usb1d6b,0002";
> > > + reg = <01>;
> > > + #address-cells = <1>;
> > > + #size-cells = <0>;
> > > +
> > > + ethernet: usbether@01 {
> > > + compatible = "usb0424,9514";
> > > + reg = <01>;
> > > + };
> > > + };
> > > +};
> > 
> > For reference, on RPi2:
> 
> Using "lsusb -t" you may get bus topology.
> 
> > Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
> > SMSC9512/9514 Fast Ethernet Adapter
> 
> It is the ethernet device, you may need to change vid/pid in dts. 
> 
> > Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
> > SMC9514 Hub
> 
> It is the hub device, you may need to change vid/pid in dts.
> 
> > Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
> > 
>  
> It is root hub, it doesn't need to be described at dts.

Thank you; neither of the vid/pid pairs in the original submission is
okay. I'll follow up with an updated version.

I've also checked this on RPi B rev2; and I'll be including that one,
and the RPI2 too.

I can't find my rev1 RPi B; but maybe I can just do the same for the
same board. It would likely work, but I may get the vid/pid wrong if
it's different from rev2. 

> Best regards,
> Peter

Thanks
Lubo


Re: [PATCH v2 04/10] crypto/compress: add asynchronous compression support

2016-02-03 Thread Joonsoo Kim
2016-02-04 12:28 GMT+09:00 Herbert Xu :
> On Thu, Feb 04, 2016 at 11:25:27AM +0800, Li, Weigang wrote:
>>
>> Please can you advise how to get the acomp patch accepted?
>
> Can you do a posting of these patches without scomp so we can
> evaluate the effects?
>

Do you think not to merge scomp? Please let me know your overall
plan about this.?

Thanks.


[PATCH v1 1/3] /proc/kpageflags: return KPF_BUDDY for "tail" buddy pages

2016-02-03 Thread Naoya Horiguchi
Currently /proc/kpageflags returns nothing for "tail" buddy pages, which
is inconvenient when grasping how free pages are distributed. This patch
sets KPF_BUDDY for such pages.

With this patch:

  $ grep MemFree /proc/meminfo ; tools/vm/page-types -b buddy
  MemFree: 3134992 kB
   flags  page-count   MB  symbolic-flags   
  long-symbolic-flags
  0x0400  779272 3044  
__B___ buddy
  0x0c004385   17  
__BM__ buddy,mmap
   total  783657 3061

783657 pages is 3134628 kB (roughly consistent with the global counter,)
so it's OK.

Signed-off-by: Naoya Horiguchi 
---
 fs/proc/page.c | 2 ++
 include/linux/page-flags.h | 2 ++
 mm/internal.h  | 3 ---
 mm/page_alloc.c| 2 --
 4 files changed, 4 insertions(+), 5 deletions(-)

diff --git v4.5-rc2-mmotm-2016-02-02-17-08/fs/proc/page.c 
v4.5-rc2-mmotm-2016-02-02-17-08_patched/fs/proc/page.c
index b2855ee..42998bb 100644
--- v4.5-rc2-mmotm-2016-02-02-17-08/fs/proc/page.c
+++ v4.5-rc2-mmotm-2016-02-02-17-08_patched/fs/proc/page.c
@@ -148,6 +148,8 @@ u64 stable_page_flags(struct page *page)
 */
if (PageBuddy(page))
u |= 1 << KPF_BUDDY;
+   else if (page_count(page) == 0 && is_free_buddy_page(page))
+   u |= 1 << KPF_BUDDY;
 
if (PageBalloon(page))
u |= 1 << KPF_BALLOON;
diff --git v4.5-rc2-mmotm-2016-02-02-17-08/include/linux/page-flags.h 
v4.5-rc2-mmotm-2016-02-02-17-08_patched/include/linux/page-flags.h
index 19724e6..5976955 100644
--- v4.5-rc2-mmotm-2016-02-02-17-08/include/linux/page-flags.h
+++ v4.5-rc2-mmotm-2016-02-02-17-08_patched/include/linux/page-flags.h
@@ -593,6 +593,8 @@ static inline void __ClearPageBuddy(struct page *page)
atomic_set(>_mapcount, -1);
 }
 
+extern bool is_free_buddy_page(struct page *page);
+
 #define PAGE_BALLOON_MAPCOUNT_VALUE (-256)
 
 static inline int PageBalloon(struct page *page)
diff --git v4.5-rc2-mmotm-2016-02-02-17-08/mm/internal.h 
v4.5-rc2-mmotm-2016-02-02-17-08_patched/mm/internal.h
index 271ad95..06071af 100644
--- v4.5-rc2-mmotm-2016-02-02-17-08/mm/internal.h
+++ v4.5-rc2-mmotm-2016-02-02-17-08_patched/mm/internal.h
@@ -145,9 +145,6 @@ extern int __isolate_free_page(struct page *page, unsigned 
int order);
 extern void __free_pages_bootmem(struct page *page, unsigned long pfn,
unsigned int order);
 extern void prep_compound_page(struct page *page, unsigned int order);
-#ifdef CONFIG_MEMORY_FAILURE
-extern bool is_free_buddy_page(struct page *page);
-#endif
 extern int user_min_free_kbytes;
 
 #if defined CONFIG_COMPACTION || defined CONFIG_CMA
diff --git v4.5-rc2-mmotm-2016-02-02-17-08/mm/page_alloc.c 
v4.5-rc2-mmotm-2016-02-02-17-08_patched/mm/page_alloc.c
index 555b9d2..d9c8b70 100644
--- v4.5-rc2-mmotm-2016-02-02-17-08/mm/page_alloc.c
+++ v4.5-rc2-mmotm-2016-02-02-17-08_patched/mm/page_alloc.c
@@ -7182,7 +7182,6 @@ __offline_isolated_pages(unsigned long start_pfn, 
unsigned long end_pfn)
 }
 #endif
 
-#ifdef CONFIG_MEMORY_FAILURE
 bool is_free_buddy_page(struct page *page)
 {
struct zone *zone = page_zone(page);
@@ -7201,4 +7200,3 @@ bool is_free_buddy_page(struct page *page)
 
return order < MAX_ORDER;
 }
-#endif
-- 
2.7.0



[PATCH v1 2/3] /proc/kpageflags: return KPF_SLAB for slab tail pages

2016-02-03 Thread Naoya Horiguchi
Currently /proc/kpageflags returns just KPF_COMPOUND_TAIL for slab tail pages,
which is inconvenient when grasping how slab pages are distributed (userspace
always needs to check which kind of tail pages by itself). This patch sets
KPF_SLAB for such pages.

With this patch:

  $ grep Slab /proc/meminfo ; tools/vm/page-types -b slab
  Slab:  64880 kB
   flags  page-count   MB  symbolic-flags   
  long-symbolic-flags
  0x0080   16220   63  
___S__ slab
   total   16220   63

16220 pages equals to 64880 kB, so returned result is consistent with the
global counter.

Signed-off-by: Naoya Horiguchi 
---
 fs/proc/page.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git v4.5-rc2-mmotm-2016-02-02-17-08/fs/proc/page.c 
v4.5-rc2-mmotm-2016-02-02-17-08_patched/fs/proc/page.c
index 42998bb..40a4685 100644
--- v4.5-rc2-mmotm-2016-02-02-17-08/fs/proc/page.c
+++ v4.5-rc2-mmotm-2016-02-02-17-08_patched/fs/proc/page.c
@@ -160,6 +160,8 @@ u64 stable_page_flags(struct page *page)
u |= kpf_copy_bit(k, KPF_LOCKED,PG_locked);
 
u |= kpf_copy_bit(k, KPF_SLAB,  PG_slab);
+   if (PageTail(page) && PageSlab(compound_head(page)))
+   u |= 1 << KPF_SLAB;
 
u |= kpf_copy_bit(k, KPF_ERROR, PG_error);
u |= kpf_copy_bit(k, KPF_DIRTY, PG_dirty);
-- 
2.7.0



[PATCH v1 3/3] tools/vm/page-types.c: support swap entry

2016-02-03 Thread Naoya Horiguchi
/proc/pid/pagemap (pte_to_pagemap_entry() internally) already reports about
swap entry, so let's make the in-kernel utility aware of it.

Signed-off-by: Naoya Horiguchi 
---
 tools/vm/page-types.c | 30 +-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git v4.5-rc2-mmotm-2016-02-02-17-08/tools/vm/page-types.c 
v4.5-rc2-mmotm-2016-02-02-17-08_patched/tools/vm/page-types.c
index 5a60162..ec62ab4 100644
--- v4.5-rc2-mmotm-2016-02-02-17-08/tools/vm/page-types.c
+++ v4.5-rc2-mmotm-2016-02-02-17-08_patched/tools/vm/page-types.c
@@ -61,6 +61,8 @@
 #define PM_PFRAME_BITS 55
 #define PM_PFRAME_MASK ((1LL << PM_PFRAME_BITS) - 1)
 #define PM_PFRAME(x)   ((x) & PM_PFRAME_MASK)
+#define MAX_SWAPFILES_SHIFT5
+#define PM_SWAP_OFFSET(x)  (((x) & PM_PFRAME_MASK) >> MAX_SWAPFILES_SHIFT)
 #define PM_SOFT_DIRTY  (1ULL << 55)
 #define PM_MMAP_EXCLUSIVE  (1ULL << 56)
 #define PM_FILE(1ULL << 61)
@@ -92,7 +94,8 @@
 #define KPF_SLOB_FREE  49
 #define KPF_SLUB_FROZEN50
 #define KPF_SLUB_DEBUG 51
-#define KPF_FILE   62
+#define KPF_FILE   61
+#define KPF_SWAP   62
 #define KPF_MMAP_EXCLUSIVE 63
 
 #define KPF_ALL_BITS   ((uint64_t)~0ULL)
@@ -146,6 +149,7 @@ static const char * const page_flag_names[] = {
[KPF_SLUB_DEBUG]= "E:slub_debug",
 
[KPF_FILE]  = "F:file",
+   [KPF_SWAP]  = "w:swap",
[KPF_MMAP_EXCLUSIVE]= "1:mmap_exclusive",
 };
 
@@ -297,6 +301,10 @@ static unsigned long pagemap_pfn(uint64_t val)
return pfn;
 }
 
+static unsigned long pagemap_swap_offset(uint64_t val)
+{
+   return val & PM_SWAP ? PM_SWAP_OFFSET(val) : 0;
+}
 
 /*
  * page flag names
@@ -452,6 +460,8 @@ static uint64_t expand_overloaded_flags(uint64_t flags, 
uint64_t pme)
flags |= BIT(SOFTDIRTY);
if (pme & PM_FILE)
flags |= BIT(FILE);
+   if (pme & PM_SWAP)
+   flags |= BIT(SWAP);
if (pme & PM_MMAP_EXCLUSIVE)
flags |= BIT(MMAP_EXCLUSIVE);
 
@@ -613,6 +623,22 @@ static void walk_pfn(unsigned long voffset,
}
 }
 
+static void walk_swap(unsigned long voffset, uint64_t pme)
+{
+   uint64_t flags = kpageflags_flags(0, pme);
+
+   if (!bit_mask_ok(flags))
+   return;
+
+   if (opt_list == 1)
+   show_page_range(voffset, pagemap_swap_offset(pme), 1, flags);
+   else if (opt_list == 2)
+   show_page(voffset, pagemap_swap_offset(pme), flags);
+
+   nr_pages[hash_slot(flags)]++;
+   total_pages++;
+}
+
 #define PAGEMAP_BATCH  (64 << 10)
 static void walk_vma(unsigned long index, unsigned long count)
 {
@@ -632,6 +658,8 @@ static void walk_vma(unsigned long index, unsigned long 
count)
pfn = pagemap_pfn(buf[i]);
if (pfn)
walk_pfn(index + i, pfn, 1, buf[i]);
+   if (buf[i] & PM_SWAP)
+   walk_swap(index + i, buf[i]);
}
 
index += pages;
-- 
2.7.0



Re: [RFC PATCH] alispinlock: acceleration from lock integration on multi-core platform

2016-02-03 Thread Ling Ma
> I have 2 major comments here. First of all, you should break up your patch
> into smaller ones. Large patch like the one in the tar ball is hard to
> review.

Ok, we will do it.

>Secondly, you are modifying over 1000 lines of code in mm/slab.c
> with some modest increase in performance. That can be hard to justify. Maybe
> you should find other use cases that involve less changes, but still have
> noticeable performance improvement. That will make it easier to be accepted.

In order to be justified the attachment in this letter include 3 files:

1. user space code (thread.c), which  can cause lots of hot kernel spinlock from
__kmalloc and kfree on multi-core platform

2. ali_work_queue.patch , the kernel patch for 4.3.0-rc4,
when we  run user space code (thread.c) based on the patch,
the synchronous operation consumption from __kmalloc and kfree is
about 15% on Intel E5-2699V3

3. org_spin_lock.patch, which is based on above ali_work_queue.patch,
when we  run user space code thread.c based on the patch,
the synchronous operation consumption from __kmalloc and kfree is
about 25% on Intel E5-2699V3


the main difference between ali_work_queue.patch and
org_spin_lock.patch as below:

diff --git a/mm/slab.h b/mm/slab.h
...
-   ali_spinlock_t list_lock;
+   spinlock_t list_lock;
...

diff --git a/mm/slab.c b/mm/slab.c
...
-   alispinlock(lock, );
+   spin_lock((spinlock_t *)lock);
+   fn(para);
+   spin_unlock((spinlock_t *)lock);
...

The above operations remove all performance noise from program modification.

We run  user space code thread.c with ali_work_queue.patch, and
org_spin_lock.patch respectively
 the output from thread.c as below:

ORG NEW
38923684 43380604
38100464 44163011
37769241 43354266
37908638 43554022
37900994 43457066
38495073 43421394
37340217 43146352
38083979 43506951
37713263 43775215
37749871 43487289
37843224 43366055
38173823 43270225
38303612 43214675
37886717 44083950
37736455 43060728
37529307 44607597
38862690 43541484
37992824 44749925
38013454 43572225
37783135 45240502
37745372 44712540
38721413 43584658
38097842 43235392

ORGNEW
TOTAL 874675292 1005486126

So the data tell us the new mechanism can improve performance 14% (
1005486126/874675292) ,
and the operation can be justified fairly.

Thanks
Ling

2016-02-04 5:42 GMT+08:00 Waiman Long :
> On 02/02/2016 11:40 PM, Ling Ma wrote:
>>
>> Longman,
>>
>> The attachment include user space code(thread.c), and kernel
>> patch(ali_work_queue.patch) based on 4.3.0-rc4,
>> we replaced all original spinlock (list_lock) in slab.h/c  with the
>> new mechanism.
>>
>> The thread.c in user space caused lots of hot kernel spinlock from
>> __kmalloc and kfree,
>> perf top -d1 shows ~25%  before ali_work_queue.patch,after appending
>> this patch ,
>> the synchronous operation consumption from __kmalloc and kfree is
>> reduced from 25% to ~15% on Intel E5-2699V3
>> (we also observed the output from user space code (thread.c) is
>> improved clearly)
>
>
> I have 2 major comments here. First of all, you should break up your patch
> into smaller ones. Large patch like the one in the tar ball is hard to
> review. Secondly, you are modifying over 1000 lines of code in mm/slab.c
> with some modest increase in performance. That can be hard to justify. Maybe
> you should find other use cases that involve less changes, but still have
> noticeable performance improvement. That will make it easier to be accepted.
>
> Cheers,
> Longman
>
>


ali_work_queue.tar.bz2
Description: BZip2 compressed data


Re: [PATCH V3 5/5] rtc: max77686: move initialisation of rtc regmap, irq chip locally

2016-02-03 Thread Krzysztof Kozlowski
On 04.02.2016 11:03, Laxman Dewangan wrote:
> 
> On Thursday 04 February 2016 05:40 AM, Krzysztof Kozlowski wrote:
>> On 03.02.2016 22:47, Laxman Dewangan wrote:
>>>
>>> Changes from V2:
>>> - Taken care of missed sequence for removing the resource.
>>> - Fix the crash when doing unbind by using requested_threaded_irq()
>>>instead of demv_requested_threaded_irq().
>>>
>>>   drivers/mfd/max77686.c   |  85 +---
>>>   drivers/rtc/rtc-max77686.c   | 148
>>> ++-
>>>   include/linux/mfd/max77686-private.h |   3 -
>>>   3 files changed, 130 insertions(+), 106 deletions(-)
>>>
>> Looks good and works properly (RTC, unbind/rebind, wakealarm again)
>> but... after applying this patch the device cannot suspend to RAM after
>> unbind/rebind.
>>
>> Reproduce path, after booting:
>> $ echo max77686-rtc > /sys/bus/platform/drivers/max77686-rtc/unbind
>> $ echo max77686-rtc > /sys/bus/platform/drivers/max77686-rtc/bind
>> $ rtcwake -d rtc2 -m mem -s 5 -v
>> (or instead of rtcwake: echo mem > /sys/power/state)
> 
> 
> My device does not support suspend and hence I can nto test this part
> and need your help to debug it.
> 
> Few question to narrow down:
> 1. Have you try to bind/unbind mfd driver to make sure that there is no
> inherent issue in the framework driver?

That might be tricky... there are also regulator and clock drivers.  I
would have to disable them... It might take me some time to prepare an
environment for this.

> 
> 2. Does suspend entry and wake alarm work if you dont do unbind and just
> bind it and enter into suspend?
If by "just bind" you mean bind during system boot, then answer is yes.
Without the unbind+bind, the system suspends correctly.

Without your patch, system suspends correctly always (no rebind, rebind
etc.).

Actually I don't have to re-bind the RTC. Just:
$ echo max77686-rtc > /sys/bus/platform/drivers/max77686-rtc/unbind
$ echo mem > /sys/power/state
triggers the issue.

> 
> 3. Can you try locally to not use devm_regmap_init_i2c() and just use
> the regmap_init_i2c() and proper removal of this from error path and
> remove callback?

I'll try to find some time for that. Maybe tomorrow.

BR,
Krzysztof

> Three things we are doing new on this movement, i2c client creating,
> regmap_init and adding irq chip.
> And probably some issue on this calls?
> Let's try with not using devm_ * for this calls?
> 
> 
> 
> 



Re: [PATCH v6] i2c: mt8173: add 4GB mode support in i2c driver.

2016-02-03 Thread Yingjoe Chen
On Tue, 2016-02-02 at 01:19 +0800, Liguo Zhang wrote:
> If 4GB mode is enable, we should add 4gb mode support in i2c driver.
> Set 4GB mode register to support 4GB mode.
> 
> Signed-off-by: Liguo Zhang 
> ---
> change in v6:
> Remove unnecessary init for reg_4g_mode.
> change in v5:
> Use BIT_ULL() to fix kernel building warning.
> change in v4:
> Use BIT_ULL() to fix kernel building warning.
> change in v3:
> Only inline the computation of reg_4g_mode in mtk_i2c_set_4g_mode().
> change in v2:
> Define a static inline function mtk_i2c_set_4g_mode() for support 4g mode.
> ---
>  drivers/i2c/busses/i2c-mt65xx.c | 42 
> +
>  1 file changed, 42 insertions(+)


Looks good to me, Thanks.

Reviewed-by: Yingjoe Chen 

Joe.C




Re: [PATCH 4/5] mm, oom_reaper: report success/failure

2016-02-03 Thread Michal Hocko
On Wed 03-02-16 15:10:57, David Rientjes wrote:
> On Wed, 3 Feb 2016, Michal Hocko wrote:
> 
> > diff --git a/mm/oom_kill.c b/mm/oom_kill.c
> > index 8e345126d73e..b87acdca2a41 100644
> > --- a/mm/oom_kill.c
> > +++ b/mm/oom_kill.c
> > @@ -420,6 +420,7 @@ static struct task_struct *oom_reaper_th;
> >  static struct task_struct *task_to_reap;
> >  static DECLARE_WAIT_QUEUE_HEAD(oom_reaper_wait);
> >  
> > +#define K(x) ((x) << (PAGE_SHIFT-10))
> >  static bool __oom_reap_task(struct task_struct *tsk)
> >  {
> > struct mmu_gather tlb;
> > @@ -476,6 +477,11 @@ static bool __oom_reap_task(struct task_struct *tsk)
> > }
> > }
> > tlb_finish_mmu(, 0, -1);
> > +   pr_info("oom_reaper: reaped process :%d (%s) anon-rss:%lukB, 
> > file-rss:%lukB, shmem-rss:%lulB\n",
> > +   task_pid_nr(tsk), tsk->comm,
> > +   K(get_mm_counter(mm, MM_ANONPAGES)),
> > +   K(get_mm_counter(mm, MM_FILEPAGES)),
> > +   K(get_mm_counter(mm, MM_SHMEMPAGES)));
> > up_read(>mmap_sem);
> >  
> > /*
> 
> This is a bit misleading, it would appear that the rss values are what was 
> reaped when in fact they represent just the values of the mm being reaped.  
> We have already printed these values as an artifact in the kernel log.

Yes and the idea was to provide the after state to compare before and
after. That's why I have kept the similar format. Just dropped the
virtual memory size because that doesn't make any sense in this context
now.

> I think it would be helpful to show anon-rss after reaping, however, so we 
> can compare to the previous anon-rss that was reported.  And, I agree that 
> leaving behind a message in the kernel log that reaping has been 
> successful is worthwhile.  So this line should just show what anon-rss is 
> after reaping and make it clear that this is not the memory reaped.

Does
"oom_reaper: reaped process %d (%s) current memory anon-rss:%lukB, 
file-rss:%lukB, shmem-rss:%lukB "

sound any better?
-- 
Michal Hocko
SUSE Labs


Re: [PATCH] ARM: DRA7: hwmod: Fix OCP2SCP sysconfig

2016-02-03 Thread Kishon Vijay Abraham I
Hi,

On Thursday 04 February 2016 12:01 PM, Kishon Vijay Abraham I wrote:
> OCP2SCP doesn't support smart idle wakeup according to
> DRA72x_SR1.0_NDA_TRM_vL and DRA75x_DRA74x_SR1.1_NDA_TRM_vW.

Ignore this patch. I'll re-send the patch with a public TRM link.

Thanks
Kishon

> Remove SIDLE_SMART_WKUP from the list of supported SIDLE modes
> in hwmod data.
> 
> Signed-off-by: Kishon Vijay Abraham I 
> ---
>  arch/arm/mach-omap2/omap_hwmod_7xx_data.c |3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/arch/arm/mach-omap2/omap_hwmod_7xx_data.c 
> b/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
> index 848356e..84c2699 100644
> --- a/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
> +++ b/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
> @@ -1482,8 +1482,7 @@ static struct omap_hwmod_class_sysconfig 
> dra7xx_ocp2scp_sysc = {
>   .syss_offs  = 0x0014,
>   .sysc_flags = (SYSC_HAS_AUTOIDLE | SYSC_HAS_SIDLEMODE |
>  SYSC_HAS_SOFTRESET | SYSS_HAS_RESET_STATUS),
> - .idlemodes  = (SIDLE_FORCE | SIDLE_NO | SIDLE_SMART |
> -SIDLE_SMART_WKUP),
> + .idlemodes  = (SIDLE_FORCE | SIDLE_NO | SIDLE_SMART),
>   .sysc_fields= _hwmod_sysc_type1,
>  };
>  
> 


Re: [PATCH] usb: rework CONFIG_USB_COMMON logic

2016-02-03 Thread Peter Chen
On Wed, Feb 03, 2016 at 11:35:26PM +0100, Arnd Bergmann wrote:
> The phy-am335x driver selects 'USB_COMMON', but all other drivers
> use 'depends on' for that symbol, and it depends on USB || USB_GADGET
> itself, which causes a Kconfig warning:
> 
> warning: (AM335X_PHY_USB) selects USB_COMMON which has unmet direct 
> dependencies (USB_SUPPORT && (USB || USB_GADGET))
> 
> As suggested by Felipe Balbi, this turns the logic around, and makes
> 'USB_COMMON' selected by everything else that needs it, so we can
> remove the dependencies.
> 
> Fixes: 59f042f644c5 ("usb: phy: phy-am335x: bypass first VBUS sensing for 
> host-only mode")
> Signed-off-by: Arnd Bergmann 
> ---
> Preliminary for now, I've added it to my patch stack for randconfig tests
> and will test it overnight to see if any build-time regressions come up.
> 
> diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
> index e7e117d5dbbe..df005f5a0e0c 100644
> --- a/drivers/phy/Kconfig
> +++ b/drivers/phy/Kconfig
> @@ -249,7 +249,8 @@ config PHY_SUN9I_USB
>   tristate "Allwinner sun9i SoC USB PHY driver"
>   depends on ARCH_SUNXI && HAS_IOMEM && OF
>   depends on RESET_CONTROLLER
> - depends on USB_COMMON
> + depends on USB_SUPPORT
> + select USB_COMMON
>   select GENERIC_PHY
>   help
> Enable this to support the transceiver that is part of Allwinner
> diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
> index 8ed451dd651e..8689dcba5201 100644
> --- a/drivers/usb/Kconfig
> +++ b/drivers/usb/Kconfig
> @@ -31,8 +31,6 @@ if USB_SUPPORT
>  
>  config USB_COMMON
>   tristate
> - default y
> - depends on USB || USB_GADGET
>  
>  config USB_ARCH_HAS_HCD
>   def_bool y
> @@ -41,6 +39,7 @@ config USB_ARCH_HAS_HCD
>  config USB
>   tristate "Support for Host-side USB"
>   depends on USB_ARCH_HAS_HCD
> + select USB_COMMON
>   select NLS  # for UTF-8 strings
>   ---help---
> Universal Serial Bus (USB) is a specification for a serial bus
> diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
> index af5d922a8f5d..2057add439f0 100644
> --- a/drivers/usb/gadget/Kconfig
> +++ b/drivers/usb/gadget/Kconfig
> @@ -15,6 +15,7 @@
>  
>  menuconfig USB_GADGET
>   tristate "USB Gadget Support"
> + select USB_COMMON
>   select NLS
>   help
>  USB is a master/slave protocol, organized with one master
> 

Reviewed-by: Peter Chen 

-- 

Best Regards,
Peter Chen


Re: [PATCH V2 7/7] cpufreq: Remove cpufreq_governor_lock

2016-02-03 Thread Viresh Kumar
On 03-02-16, 19:32, Viresh Kumar wrote:
> We used to drop policy->rwsem just before calling __cpufreq_governor()
> in some cases earlier and so it was possible that __cpufreq_governor()
> runs concurrently via separate threads.
> 
> In order to guarantee valid state transitions for governors,
> 'governor_enabled' was required to be protected using some locking and
> we created cpufreq_governor_lock for that.
> 
> But now, __cpufreq_governor() is always called from within policy->rwsem
> held and so 'governor_enabled' is protected against races even without
> cpufreq_governor_lock.
> 
> Get rid of the extra lock now.
> 
> Signed-off-by: Viresh Kumar 
> ---
>  drivers/cpufreq/cpufreq.c | 7 ---
>  1 file changed, 7 deletions(-)
> 
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 4fc3889ca7c9..7bc8a5ed97e5 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -102,7 +102,6 @@ static LIST_HEAD(cpufreq_governor_list);
>  static struct cpufreq_driver *cpufreq_driver;
>  static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data);
>  static DEFINE_RWLOCK(cpufreq_driver_lock);
> -DEFINE_MUTEX(cpufreq_governor_lock);
>  
>  /* Flag to suspend/resume CPUFreq governors */
>  static bool cpufreq_suspended;
> @@ -1963,11 +1962,9 @@ static int __cpufreq_governor(struct cpufreq_policy 
> *policy,
>  
>   pr_debug("%s: for CPU %u, event %u\n", __func__, policy->cpu, event);
>  
> - mutex_lock(_governor_lock);
>   if ((policy->governor_enabled && event == CPUFREQ_GOV_START)
>   || (!policy->governor_enabled
>   && (event == CPUFREQ_GOV_LIMITS || event == CPUFREQ_GOV_STOP))) {
> - mutex_unlock(_governor_lock);
>   return -EBUSY;
>   }
>  
> @@ -1976,8 +1973,6 @@ static int __cpufreq_governor(struct cpufreq_policy 
> *policy,
>   else if (event == CPUFREQ_GOV_START)
>   policy->governor_enabled = true;
>  
> - mutex_unlock(_governor_lock);
> -
>   ret = policy->governor->governor(policy, event);
>  
>   if (!ret) {
> @@ -1987,12 +1982,10 @@ static int __cpufreq_governor(struct cpufreq_policy 
> *policy,
>   policy->governor->initialized--;
>   } else {
>   /* Restore original values */
> - mutex_lock(_governor_lock);
>   if (event == CPUFREQ_GOV_STOP)
>   policy->governor_enabled = true;
>   else if (event == CPUFREQ_GOV_START)
>   policy->governor_enabled = false;
> - mutex_unlock(_governor_lock);
>   }
>  
>   if (((event == CPUFREQ_GOV_POLICY_INIT) && ret) ||

+ minor cleanup:

diff --git a/drivers/cpufreq/cpufreq_governor.h 
b/drivers/cpufreq/cpufreq_governor.h
index ed328a39c4ac..7bed63e14e7d 100644
--- a/drivers/cpufreq/cpufreq_governor.h
+++ b/drivers/cpufreq/cpufreq_governor.h
@@ -214,7 +214,6 @@ static inline int delay_for_sampling_rate(unsigned int 
sampling_rate)
return delay;
 }
 
-extern struct mutex cpufreq_governor_lock;
 extern const struct sysfs_ops governor_sysfs_ops;
 
 void gov_add_timers(struct cpufreq_policy *policy, unsigned int delay);

-- 
viresh


Re: [PATCH 1/5] mm, oom: introduce oom reaper

2016-02-03 Thread Michal Hocko
On Wed 03-02-16 15:48:18, David Rientjes wrote:
> On Wed, 3 Feb 2016, Michal Hocko wrote:
> 
> > From: Michal Hocko 
> > 
> > This is based on the idea from Mel Gorman discussed during LSFMM 2015 and
> > independently brought up by Oleg Nesterov.
> > 
> > The OOM killer currently allows to kill only a single task in a good
> > hope that the task will terminate in a reasonable time and frees up its
> > memory.  Such a task (oom victim) will get an access to memory reserves
> > via mark_oom_victim to allow a forward progress should there be a need
> > for additional memory during exit path.
> > 
> > It has been shown (e.g. by Tetsuo Handa) that it is not that hard to
> > construct workloads which break the core assumption mentioned above and
> > the OOM victim might take unbounded amount of time to exit because it
> > might be blocked in the uninterruptible state waiting for an event
> > (e.g. lock) which is blocked by another task looping in the page
> > allocator.
> > 
> > This patch reduces the probability of such a lockup by introducing a
> > specialized kernel thread (oom_reaper) which tries to reclaim additional
> > memory by preemptively reaping the anonymous or swapped out memory
> > owned by the oom victim under an assumption that such a memory won't
> > be needed when its owner is killed and kicked from the userspace anyway.
> > There is one notable exception to this, though, if the OOM victim was
> > in the process of coredumping the result would be incomplete. This is
> > considered a reasonable constrain because the overall system health is
> > more important than debugability of a particular application.
> > 
> > A kernel thread has been chosen because we need a reliable way of
> > invocation so workqueue context is not appropriate because all the
> > workers might be busy (e.g. allocating memory). Kswapd which sounds
> > like another good fit is not appropriate as well because it might get
> > blocked on locks during reclaim as well.
> > 
> > oom_reaper has to take mmap_sem on the target task for reading so the
> > solution is not 100% because the semaphore might be held or blocked for
> > write but the probability is reduced considerably wrt. basically any
> > lock blocking forward progress as described above. In order to prevent
> > from blocking on the lock without any forward progress we are using only
> > a trylock and retry 10 times with a short sleep in between.
> > Users of mmap_sem which need it for write should be carefully reviewed
> > to use _killable waiting as much as possible and reduce allocations
> > requests done with the lock held to absolute minimum to reduce the risk
> > even further.
> > 
> > The API between oom killer and oom reaper is quite trivial. wake_oom_reaper
> > updates mm_to_reap with cmpxchg to guarantee only NULL->mm transition
> > and oom_reaper clear this atomically once it is done with the work. This
> > means that only a single mm_struct can be reaped at the time. As the
> > operation is potentially disruptive we are trying to limit it to the
> > ncessary minimum and the reaper blocks any updates while it operates on
> > an mm. mm_struct is pinned by mm_count to allow parallel exit_mmap and a
> > race is detected by atomic_inc_not_zero(mm_users).
> > 
> > Chnages since v4
> > - drop MAX_RT_PRIO-1 as per David - memcg/cpuset/mempolicy OOM killing
> >   might interfere with the rest of the system
> > Changes since v3
> > - many style/compile fixups by Andrew
> > - unmap_mapping_range_tree needs full initialization of zap_details
> >   to prevent from missing unmaps and follow up BUG_ON during truncate
> >   resp. misaccounting - Kirill/Andrew
> > - exclude mlocked pages because they need an explicit munlock by Kirill
> > - use subsys_initcall instead of module_init - Paul Gortmaker
> > - do not tear down mm if it is shared with the global init because this
> >   could lead to SEGV and panic - Tetsuo
> > Changes since v2
> > - fix mm_count refernce leak reported by Tetsuo
> > - make sure oom_reaper_th is NULL after kthread_run fails - Tetsuo
> > - use wait_event_freezable rather than open coded wait loop - suggested
> >   by Tetsuo
> > Changes since v1
> > - fix the screwed up detail->check_swap_entries - Johannes
> > - do not use kthread_should_stop because that would need a cleanup
> >   and we do not have anybody to stop us - Tetsuo
> > - move wake_oom_reaper to oom_kill_process because we have to wait
> >   for all tasks sharing the same mm to get killed - Tetsuo
> > - do not reap mm structs which are shared with unkillable tasks - Tetsuo
> > 
> > Suggested-by: Oleg Nesterov 
> > Suggested-by: Mel Gorman 
> > Acked-by: Mel Gorman 
> > Signed-off-by: Michal Hocko 
> 
> Acked-by: David Rientjes 

Thanks!
 
> I think all the patches could really have been squashed together because 
> subsequent patches just overwrite already added code. 

The primary reason is a better bisectability and incremental nature of
changes.

> I was going to 
> suggest not doing 

Re: Crashes with 874bbfe600a6 in 3.18.25

2016-02-03 Thread Michal Hocko
On Wed 03-02-16 11:59:01, Tejun Heo wrote:
> On Wed, Feb 03, 2016 at 05:48:52PM +0100, Michal Hocko wrote:
[...]
> > anything and add_timer_on also for WORK_CPU_UNBOUND is really required
> > then we should at least preserve WORK_CPU_UNBOUND in dwork->cpu so that
> > __queue_work can actually move on to the local CPU properly and handle
> > the offline cpu properly.
> 
> delayed_work->cpu is determined on queueing time.  Dealing with
> offlined cpus at execution is completley fine.  There's no need to
> "preserve" anything.

I've seen you have posted a fix in the mean time but just for my
understading. Why the following is not an appropriate fix?

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index c579dbab2e36..52bb11cf20d1 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1459,9 +1459,9 @@ static void __queue_delayed_work(int cpu, struct 
workqueue_struct *wq,
 
dwork->wq = wq;
/* timer isn't guaranteed to run in this cpu, record earlier */
+   dwork->cpu = cpu;
if (cpu == WORK_CPU_UNBOUND)
cpu = raw_smp_processor_id();
-   dwork->cpu = cpu;
timer->expires = jiffies + delay;
 
add_timer_on(timer, cpu);

Thanks!
-- 
Michal Hocko
SUSE Labs


[PATCH] ARM: DRA7: hwmod: Fix OCP2SCP sysconfig

2016-02-03 Thread Kishon Vijay Abraham I
OCP2SCP doesn't support smart idle wakeup according to
DRA72x_SR1.0_NDA_TRM_vL and DRA75x_DRA74x_SR1.1_NDA_TRM_vW.
Remove SIDLE_SMART_WKUP from the list of supported SIDLE modes
in hwmod data.

Signed-off-by: Kishon Vijay Abraham I 
---
 arch/arm/mach-omap2/omap_hwmod_7xx_data.c |3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/arm/mach-omap2/omap_hwmod_7xx_data.c 
b/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
index 848356e..84c2699 100644
--- a/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
@@ -1482,8 +1482,7 @@ static struct omap_hwmod_class_sysconfig 
dra7xx_ocp2scp_sysc = {
.syss_offs  = 0x0014,
.sysc_flags = (SYSC_HAS_AUTOIDLE | SYSC_HAS_SIDLEMODE |
   SYSC_HAS_SOFTRESET | SYSS_HAS_RESET_STATUS),
-   .idlemodes  = (SIDLE_FORCE | SIDLE_NO | SIDLE_SMART |
-  SIDLE_SMART_WKUP),
+   .idlemodes  = (SIDLE_FORCE | SIDLE_NO | SIDLE_SMART),
.sysc_fields= _hwmod_sysc_type1,
 };
 
-- 
1.7.9.5



[PATCH v5] futex: Remove requirement for lock_page in get_futex_key

2016-02-03 Thread Davidlohr Bueso
From: Davidlohr Bueso 

From: Mel Gorman 

When dealing with key handling for shared futexes, we can drastically reduce
the usage/need of the page lock. 1) For anonymous pages, the associated futex
object is the mm_struct which does not require the page lock. 2) For inode
based, keys, we can check under RCU read lock if the page mapping is still
valid and take reference to the inode. This just leaves one rare race that
requires the page lock in the slow path when examining the swapcache.

Additionally realtime users currently have a problem with the page lock being
contended for unbounded periods of time during futex operations.

Task A
 get_futex_key()
 lock_page()
---> preempted

Now any other task trying to lock that page will have to wait until
task A gets scheduled back in, which is an unbound time.

With this patch, we pretty much have a lockless futex_get_key().

Experiments show that this patch can boost/speedup the hashing of shared
futexes with the perf futex benchmarks (which is good for measuring such
change) by up to 45% when there are high (> 100) thread counts on a 60 core
Westmere. Lower counts are pretty much in the noise range or less than 10%,
but mid range can be seen at over 30% overall throughput (hash ops/sec).
This makes anon-mem shared futexes much closer to its private counterpart.

Not-yet-signed-off-by: Peter Zijlstra 
Signed-off-by: Mel Gorman 
[ported on top of thp refcount rework, changelog, comments, fixes]
Signed-off-by: Davidlohr Bueso 
---

Changes from v4:
- Integrated feedback from Hugh, specifically:
   * check for page->mapping change with page lock held when
 detecting shm race.
   * move inode assign, if the mapping still matches what
 we expect should we have a valid inode.
   * move iput out of rcu lock.

Changes from v3:
- Redo mapping sanity check, now do not halt the kernel.

Changes from v2:

- Minor adjustments by peterz.
- Applies on top of -next-20160118

Changes from v1:
- Remove unnecesary mb, as atomic_inc returning does what we need.
- Fix bogus mapping load.
- Minor code cleanups/comments.

 kernel/futex.c | 99 +-
 1 file changed, 91 insertions(+), 8 deletions(-)

diff --git a/kernel/futex.c b/kernel/futex.c
index 5d6ce64..a00a15e 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -520,7 +520,20 @@ again:
else
err = 0;
 
-   lock_page(page);
+   /*
+* The treatment of mapping from this point on is critical. The page
+* lock protects many things but in this context the page lock
+* stabilizes mapping, prevents inode freeing in the shared
+* file-backed region case and guards against movement to swap cache.
+*
+* Strictly speaking the page lock is not needed in all cases being
+* considered here and page lock forces unnecessarily serialization
+* From this point on, mapping will be re-verified if necessary and
+* page lock will be acquired only if it is unavoidable
+*/
+   page = compound_head(page);
+   mapping = READ_ONCE(page->mapping);
+
/*
 * If page->mapping is NULL, then it cannot be a PageAnon
 * page; but it might be the ZERO_PAGE or in the gate area or
@@ -536,19 +549,31 @@ again:
 * shmem_writepage move it from filecache to swapcache beneath us:
 * an unlikely race, but we do need to retry for page->mapping.
 */
-   mapping = compound_head(page)->mapping;
-   if (!mapping) {
-   int shmem_swizzled = PageSwapCache(page);
+   if (unlikely(!mapping)) {
+   int shmem_swizzled;
+
+   /*
+* Page lock is required to identify which special case above
+* applies. If this is really a shmem page then the page lock
+* will prevent unexpected transitions.
+*/
+   lock_page(page);
+   shmem_swizzled = PageSwapCache(page) || page->mapping;
unlock_page(page);
put_page(page);
+
if (shmem_swizzled)
goto again;
+
return -EFAULT;
}
 
/*
 * Private mappings are handled in a simple way.
 *
+* If the futex key is stored on an anonymous page, then the associated
+* object is the mm which is implicitly pinned by the calling process.
+*
 * NOTE: When userspace waits on a MAP_SHARED mapping, even if
 * it's a read-only handle, it's expected that futexes attach to
 * the object not the particular process.
@@ -566,16 +591,74 @@ again:
key->both.offset |= FUT_OFF_MMSHARED; /* ref taken on mm */
key->private.mm = mm;
key->private.address = address;
+
+   get_futex_key_refs(key); /* implies MB (B) */
+
} else {
+   struct inode *inode;
+
+   /*

Re: [PATCH v2 07/22] media: v4l-core add enable/disable source common interfaces

2016-02-03 Thread kbuild test robot
Hi Shuah,

[auto build test WARNING on linuxtv-media/master]
[also build test WARNING on next-20160203]
[cannot apply to v4.5-rc2]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improving the system]

url:
https://github.com/0day-ci/linux/commits/Shuah-Khan/Sharing-media-resources-across-ALSA-and-au0828-drivers/20160204-121414
base:   git://linuxtv.org/media_tree.git master
reproduce: make htmldocs

All warnings (new ones prefixed by >>):

   include/linux/init.h:1: warning: no structured comments found
   kernel/sys.c:1: warning: no structured comments found
   drivers/dma-buf/seqno-fence.c:1: warning: no structured comments found
   drivers/dma-buf/reservation.c:1: warning: no structured comments found
   include/linux/reservation.h:1: warning: no structured comments found
>> include/media/v4l2-mc.h:114: warning: No description found for parameter 
>> 'vdev'
   include/media/v4l2-mc.h:128: warning: No description found for parameter 
'vdev'
   include/media/media-device.h:357: warning: No description found for 
parameter 'entity_notify'
   include/media/media-device.h:357: warning: No description found for 
parameter 'source_priv'
   include/media/media-device.h:357: warning: No description found for 
parameter 'enable_source'
   include/media/media-device.h:357: warning: No description found for 
parameter 'disable_source'
   include/media/media-device.h:357: warning: No description found for 
parameter 'entity_notify'
   include/media/media-device.h:357: warning: No description found for 
parameter 'source_priv'
   include/media/media-device.h:357: warning: No description found for 
parameter 'enable_source'
   include/media/media-device.h:357: warning: No description found for 
parameter 'disable_source'
   include/media/media-entity.h:840: warning: No description found for 
parameter 'entity'
   include/media/media-entity.h:840: warning: No description found for 
parameter 'pipe'
   include/media/media-entity.h:860: warning: No description found for 
parameter 'entity'
   include/linux/spi/spi.h:540: warning: No description found for parameter 
'max_transfer_size'

vim +/vdev +114 include/media/v4l2-mc.h

98  /**
99   * v4l_enable_media_source() -  Hold media source for exclusive use
   100   *  if free
   101   *
   102   * @vdev - poniter to struct video_device
   103   *
   104   * This interface calls enable_source handler to determine if
   105   * media source is free for use. The enable_source handler is
   106   * responsible for checking is the media source is free and
   107   * start a pipeline between the media source and the media
   108   * entity associated with the video device. This interface
   109   * should be called from v4l2-core and dvb-core interfaces
   110   * that change the source configuration.
   111   *
   112   * Return: returns zero on success or a negative error code.
   113   */
 > 114  int v4l_enable_media_source(struct video_device *vdev);
   115  
   116  /**
   117   * v4l_disable_media_source() - Release media source
   118   *
   119   * @vdev - poniter to struct video_device
   120   *
   121   * This interface calls disable_source handler to release
   122   * the media source. The disable_source handler stops the

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: Binary data


Re: [PATCH V2 0/7] cpufreq: governors: Fix ABBA lockups

2016-02-03 Thread Viresh Kumar
On 03-02-16, 21:40, Viresh Kumar wrote:
> On 03-02-16, 15:54, Juri Lelli wrote:
> > Ouch, I've just got this executing -f basic on Juno. :(
> > It happens with the hotplug_1_by_1 test.
> > 
> > 
> > [ 1086.531252] IRQ1 no longer affine to CPU1
> > [ 1086.531495] CPU1: shutdown
> > [ 1086.538199] psci: CPU1 killed.
> > [ 1086.583396]
> > [ 1086.584881] ==
> > [ 1086.590999] [ INFO: possible circular locking dependency detected ]
> > [ 1086.597205] 4.5.0-rc2+ #37 Not tainted
> > [ 1086.600914] ---
> > [ 1086.607118] runme.sh/1052 is trying to acquire lock:
> > [ 1086.612031]  (sb_writers#7){.+.+.+}, at: [] 
> > __sb_start_write+0xcc/0xe0
> > [ 1086.620090]
> > [ 1086.620090] but task is already holding lock:
> > [ 1086.625865]  (>rwsem){+.}, at: [] 
> > cpufreq_offline+0x7c/0x278
> > [ 1086.634081]
> > [ 1086.634081] which lock already depends on the new lock.
> > [ 1086.634081]
> > [ 1086.642180]
> > [ 1086.642180] the existing dependency chain (in reverse order) is:
> > [ 1086.649589]
> > -> #1 (>rwsem){+.}:
> > [ 1086.653929][] check_prev_add+0x670/0x754
> > [ 1086.660060][] 
> > validate_chain.isra.36+0x724/0xa0c
> > [ 1086.666876][] __lock_acquire+0x4e4/0xba0
> > [ 1086.673001][] lock_release+0x244/0x570
> > [ 1086.678955][] 
> > __mutex_unlock_slowpath+0xa0/0x18c
> > [ 1086.685771][] mutex_unlock+0x20/0x2c
> > [ 1086.691553][] kernfs_fop_write+0xb0/0x194
> > [ 1086.697768][] __vfs_write+0x48/0x104
> > [ 1086.703550][] vfs_write+0x98/0x198
> > [ 1086.709161][] SyS_write+0x54/0xb0
> > [ 1086.714684][] el0_svc_naked+0x24/0x28
> > [ 1086.720555]
> > -> #0 (sb_writers#7){.+.+.+}:
> > [ 1086.724730][] print_circular_bug+0x80/0x2e4
> > [ 1086.731116][] check_prev_add+0x13c/0x754
> > [ 1086.737243][] 
> > validate_chain.isra.36+0x724/0xa0c
> > [ 1086.744059][] __lock_acquire+0x4e4/0xba0
> > [ 1086.750184][] lock_acquire+0xe4/0x204
> > [ 1086.756052][] percpu_down_read+0x50/0xe4
> > [ 1086.762180][] __sb_start_write+0xcc/0xe0
> > [ 1086.768306][] mnt_want_write+0x28/0x54
> > [ 1086.774263][] do_last+0x660/0xcb8
> > [ 1086.779788][] path_openat+0x8c/0x2b0
> > [ 1086.785570][] do_filp_open+0x78/0xf0
> > [ 1086.791353][] do_sys_open+0x150/0x214
> > [ 1086.797222][] SyS_openat+0x3c/0x48
> > [ 1086.802831][] el0_svc_naked+0x24/0x28
> > [ 1086.808700]
> > [ 1086.808700] other info that might help us debug this:
> > [ 1086.808700]
> > [ 1086.816627]  Possible unsafe locking scenario:
> > [ 1086.816627]
> > [ 1086.822488]CPU0CPU1
> > [ 1086.826971]
> > [ 1086.831453]   lock(>rwsem);
> > [ 1086.834918]lock(sb_writers#7);
> > [ 1086.840713]lock(>rwsem);
> > [ 1086.846671]   lock(sb_writers#7);
> > [ 1086.849972]
> > [ 1086.849972]  *** DEADLOCK ***
> > [ 1086.849972]
> > [ 1086.855836] 1 lock held by runme.sh/1052:
> > [ 1086.859802]  #0:  (>rwsem){+.}, at: [] 
> > cpufreq_offline+0x7c/0x278
> > [ 1086.868453]
> > [ 1086.868453] stack backtrace:
> > [ 1086.872769] CPU: 5 PID: 1052 Comm: runme.sh Not tainted 4.5.0-rc2+ #37
> > [ 1086.879229] Hardware name: ARM Juno development board (r2) (DT)
> > [ 1086.885089] Call trace:
> > [ 1086.887511] [] dump_backtrace+0x0/0x1f4
> > [ 1086.892858] [] show_stack+0x20/0x28
> > [ 1086.897861] [] dump_stack+0x84/0xc0
> > [ 1086.902863] [] print_circular_bug+0x1d4/0x2e4
> > [ 1086.908725] [] check_prev_add+0x13c/0x754
> > [ 1086.914244] [] validate_chain.isra.36+0x724/0xa0c
> > [ 1086.920448] [] __lock_acquire+0x4e4/0xba0
> > [ 1086.925965] [] lock_acquire+0xe4/0x204
> > [ 1086.931224] [] percpu_down_read+0x50/0xe4
> > [ 1086.936742] [] __sb_start_write+0xcc/0xe0
> > [ 1086.942260] [] mnt_want_write+0x28/0x54
> > [ 1086.947605] [] do_last+0x660/0xcb8
> > [ 1086.952520] [] path_openat+0x8c/0x2b0
> > [ 1086.957693] [] do_filp_open+0x78/0xf0
> > [ 1086.962865] [] do_sys_open+0x150/0x214
> > [ 1086.968123] [] SyS_openat+0x3c/0x48
> > [ 1086.973124] [] el0_svc_naked+0x24/0x28
> > [ 1087.019315] Detected PIPT I-cache on CPU1
> > [ 1087.019373] CPU1: Booted secondary processor [410fd080]
> 
> Urg..

Urg square :(

> I failed to understand it for now though. Please test only the first 4
> patches and leave the bottom three. AFAICT, this is caused by the 6th
> patch.

>From the code I still failed to understand this since sometime back
and I something just caught my eyes and the 6th patch needs this
fixup:

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 7bc8a5ed97e5..ac3348ecde7b 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1351,7 +1351,7 @@ static void cpufreq_offline(unsigned int cpu)
  

Re: [PATCH] mm/slub: support left red zone

2016-02-03 Thread Joonsoo Kim
On Thu, Feb 04, 2016 at 03:15:50PM +0900, Joonsoo Kim wrote:
> SLUB already has red zone debugging feature. But, it is only positioned
> at the end of object(aka right red zone) so it cannot catch left oob.
> Although current object's right red zone acts as left red zone of
> previous object, first object in a slab cannot take advantage of

Oops... s/previous/next.

> this effect. This patch explicitly add left red zone to each objects
> to detect left oob more precisely.
> 
> Signed-off-by: Joonsoo Kim 
> ---
>  include/linux/slub_def.h |   1 +
>  mm/slub.c| 158 
> ++-
>  2 files changed, 115 insertions(+), 44 deletions(-)
> 
> diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
> index b7e57927..a33869b 100644
> --- a/include/linux/slub_def.h
> +++ b/include/linux/slub_def.h
> @@ -77,6 +77,7 @@ struct kmem_cache {
>   int refcount;   /* Refcount for slab cache destroy */
>   void (*ctor)(void *);
>   int inuse;  /* Offset to metadata */
> + int red_left_pad;   /* Left redzone padding size */
>   int align;  /* Alignment */
>   int reserved;   /* Reserved bytes at the end of slabs */
>   const char *name;   /* Name (only for display!) */
> diff --git a/mm/slub.c b/mm/slub.c
> index 7b5a965..7216769 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -39,6 +39,10 @@
>  
>  #include "internal.h"
>  
> +#ifdef CONFIG_KASAN
> +#include "kasan/kasan.h"
> +#endif
> +
>  /*
>   * Lock order:
>   *   1. slab_mutex (Global Mutex)
> @@ -124,6 +128,14 @@ static inline int kmem_cache_debug(struct kmem_cache *s)
>  #endif
>  }
>  
> +static inline void *fixup_red_left(struct kmem_cache *s, void *p)
> +{
> + if (kmem_cache_debug(s) && s->flags & SLAB_RED_ZONE)
> + p += s->red_left_pad;
> +
> + return p;
> +}
> +
>  static inline bool kmem_cache_has_cpu_partial(struct kmem_cache *s)
>  {
>  #ifdef CONFIG_SLUB_CPU_PARTIAL
> @@ -224,24 +236,6 @@ static inline void stat(const struct kmem_cache *s, enum 
> stat_item si)
>   *   Core slab cache functions
>   ***/
>  
> -/* Verify that a pointer has an address that is valid within a slab page */
> -static inline int check_valid_pointer(struct kmem_cache *s,
> - struct page *page, const void *object)
> -{
> - void *base;
> -
> - if (!object)
> - return 1;
> -
> - base = page_address(page);
> - if (object < base || object >= base + page->objects * s->size ||
> - (object - base) % s->size) {
> - return 0;
> - }
> -
> - return 1;
> -}
> -
>  static inline void *get_freepointer(struct kmem_cache *s, void *object)
>  {
>   return *(void **)(object + s->offset);
> @@ -435,6 +429,22 @@ static void get_map(struct kmem_cache *s, struct page 
> *page, unsigned long *map)
>   set_bit(slab_index(p, s, addr), map);
>  }
>  
> +static inline int size_from_object(struct kmem_cache *s)
> +{
> + if (s->flags & SLAB_RED_ZONE)
> + return s->size - s->red_left_pad;
> +
> + return s->size;
> +}
> +
> +static inline void *restore_red_left(struct kmem_cache *s, void *p)
> +{
> + if (s->flags & SLAB_RED_ZONE)
> + p -= s->red_left_pad;
> +
> + return p;
> +}
> +
>  /*
>   * Debug settings:
>   */
> @@ -468,6 +478,26 @@ static inline void metadata_access_disable(void)
>  /*
>   * Object debugging
>   */
> +
> +/* Verify that a pointer has an address that is valid within a slab page */
> +static inline int check_valid_pointer(struct kmem_cache *s,
> + struct page *page, void *object)
> +{
> + void *base;
> +
> + if (!object)
> + return 1;
> +
> + base = page_address(page);
> + object = restore_red_left(s, object);
> + if (object < base || object >= base + page->objects * s->size ||
> + (object - base) % s->size) {
> + return 0;
> + }
> +
> + return 1;
> +}
> +
>  static void print_section(char *text, u8 *addr, unsigned int length)
>  {
>   metadata_access_enable();
> @@ -607,7 +637,9 @@ static void print_trailer(struct kmem_cache *s, struct 
> page *page, u8 *p)
>   pr_err("INFO: Object 0x%p @offset=%tu fp=0x%p\n\n",
>  p, p - addr, get_freepointer(s, p));
>  
> - if (p > addr + 16)
> + if (s->flags & SLAB_RED_ZONE)
> + print_section("Redzone ", p - s->red_left_pad, s->red_left_pad);
> + else if (p > addr + 16)
>   print_section("Bytes b4 ", p - 16, 16);
>  
>   print_section("Object ", p, min_t(unsigned long, s->object_size,
> @@ -624,9 +656,9 @@ static void print_trailer(struct kmem_cache *s, struct 
> page *page, u8 *p)
>   if (s->flags & SLAB_STORE_USER)
>   off += 2 * sizeof(struct track);
>  
> - if (off != s->size)
> + if (off != 

[PATCH v2 3/3] mm/compaction: speed up pageblock_pfn_to_page() when zone is contiguous

2016-02-03 Thread Joonsoo Kim
There is a performance drop report due to hugepage allocation and in there
half of cpu time are spent on pageblock_pfn_to_page() in compaction [1].
In that workload, compaction is triggered to make hugepage but most of
pageblocks are un-available for compaction due to pageblock type and
skip bit so compaction usually fails. Most costly operations in this case
is to find valid pageblock while scanning whole zone range. To check
if pageblock is valid to compact, valid pfn within pageblock is required
and we can obtain it by calling pageblock_pfn_to_page(). This function
checks whether pageblock is in a single zone and return valid pfn
if possible. Problem is that we need to check it every time before
scanning pageblock even if we re-visit it and this turns out to
be very expensive in this workload.

Although we have no way to skip this pageblock check in the system
where hole exists at arbitrary position, we can use cached value for
zone continuity and just do pfn_to_page() in the system where hole doesn't
exist. This optimization considerably speeds up in above workload.

Before vs After
Max: 1096 MB/s vs 1325 MB/s
Min: 635 MB/s 1015 MB/s
Avg: 899 MB/s 1194 MB/s

Avg is improved by roughly 30% [2].

[1]: http://www.spinics.net/lists/linux-mm/msg97378.html
[2]: https://lkml.org/lkml/2015/12/9/23

v3
o remove pfn_valid_within() check for all pages in the pageblock
because pageblock_pfn_to_page() is only called with pageblock aligned pfn.

v2
o checking zone continuity after initialization
o handle memory-hotplug case

Reported and Tested-by: Aaron Lu 
Signed-off-by: Joonsoo Kim 
---
 include/linux/gfp.h|  6 
 include/linux/memory_hotplug.h |  3 ++
 include/linux/mmzone.h |  2 ++
 mm/compaction.c| 43 ---
 mm/internal.h  | 12 +++
 mm/memory_hotplug.c|  9 +
 mm/page_alloc.c| 79 +-
 7 files changed, 104 insertions(+), 50 deletions(-)

diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index 28ad5f6..bd7fccc 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -515,13 +515,7 @@ void drain_zone_pages(struct zone *zone, struct 
per_cpu_pages *pcp);
 void drain_all_pages(struct zone *zone);
 void drain_local_pages(struct zone *zone);
 
-#ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT
 void page_alloc_init_late(void);
-#else
-static inline void page_alloc_init_late(void)
-{
-}
-#endif
 
 /*
  * gfp_allowed_mask is set to GFP_BOOT_MASK during early boot to restrict what
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index 4340599..e960b78 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -196,6 +196,9 @@ void put_online_mems(void);
 void mem_hotplug_begin(void);
 void mem_hotplug_done(void);
 
+extern void set_zone_contiguous(struct zone *zone);
+extern void clear_zone_contiguous(struct zone *zone);
+
 #else /* ! CONFIG_MEMORY_HOTPLUG */
 /*
  * Stub functions for when hotplug is off
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 7b6c2cf..f12b950 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -520,6 +520,8 @@ struct zone {
boolcompact_blockskip_flush;
 #endif
 
+   boolcontiguous;
+
ZONE_PADDING(_pad3_)
/* Zone statistics */
atomic_long_t   vm_stat[NR_VM_ZONE_STAT_ITEMS];
diff --git a/mm/compaction.c b/mm/compaction.c
index 8ce36eb..93f71d9 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -71,49 +71,6 @@ static inline bool migrate_async_suitable(int migratetype)
return is_migrate_cma(migratetype) || migratetype == MIGRATE_MOVABLE;
 }
 
-/*
- * Check that the whole (or subset of) a pageblock given by the interval of
- * [start_pfn, end_pfn) is valid and within the same zone, before scanning it
- * with the migration of free compaction scanner. The scanners then need to
- * use only pfn_valid_within() check for arches that allow holes within
- * pageblocks.
- *
- * Return struct page pointer of start_pfn, or NULL if checks were not passed.
- *
- * It's possible on some configurations to have a setup like node0 node1 node0
- * i.e. it's possible that all pages within a zones range of pages do not
- * belong to a single zone. We assume that a border between node0 and node1
- * can occur within a single pageblock, but not a node0 node1 node0
- * interleaving within a single pageblock. It is therefore sufficient to check
- * the first and last page of a pageblock and avoid checking each individual
- * page in a pageblock.
- */
-static struct page *pageblock_pfn_to_page(unsigned long start_pfn,
-   unsigned long end_pfn, struct zone *zone)
-{
-   struct page *start_page;
-   struct page *end_page;
-
-   /* end_pfn is one past the range we are checking */
-   end_pfn--;
-
-   if (!pfn_valid(start_pfn) || !pfn_valid(end_pfn))
- 

[PATCH v2 2/3] mm/compaction: pass only pageblock aligned range to pageblock_pfn_to_page

2016-02-03 Thread Joonsoo Kim
pageblock_pfn_to_page() is used to check there is valid pfn and all pages
in the pageblock is in a single zone. If there is a hole in the pageblock,
passing arbitrary position to pageblock_pfn_to_page() could cause to skip
whole pageblock scanning, instead of just skipping the hole page. For
deterministic behaviour, it's better to always pass pageblock aligned
range to pageblock_pfn_to_page(). It will also help further optimization
on pageblock_pfn_to_page() in the following patch.

Signed-off-by: Joonsoo Kim 
---
 mm/compaction.c | 41 ++---
 1 file changed, 30 insertions(+), 11 deletions(-)

diff --git a/mm/compaction.c b/mm/compaction.c
index 56fa321..8ce36eb 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -555,13 +555,17 @@ unsigned long
 isolate_freepages_range(struct compact_control *cc,
unsigned long start_pfn, unsigned long end_pfn)
 {
-   unsigned long isolated, pfn, block_end_pfn;
+   unsigned long isolated, pfn, block_start_pfn, block_end_pfn;
LIST_HEAD(freelist);
 
pfn = start_pfn;
+   block_start_pfn = pfn & ~(pageblock_nr_pages - 1);
+   if (block_start_pfn < cc->zone->zone_start_pfn)
+   block_start_pfn = cc->zone->zone_start_pfn;
block_end_pfn = ALIGN(pfn + 1, pageblock_nr_pages);
 
for (; pfn < end_pfn; pfn += isolated,
+   block_start_pfn = block_end_pfn,
block_end_pfn += pageblock_nr_pages) {
/* Protect pfn from changing by isolate_freepages_block */
unsigned long isolate_start_pfn = pfn;
@@ -574,11 +578,13 @@ isolate_freepages_range(struct compact_control *cc,
 * scanning range to right one.
 */
if (pfn >= block_end_pfn) {
+   block_start_pfn = pfn & ~(pageblock_nr_pages - 1);
block_end_pfn = ALIGN(pfn + 1, pageblock_nr_pages);
block_end_pfn = min(block_end_pfn, end_pfn);
}
 
-   if (!pageblock_pfn_to_page(pfn, block_end_pfn, cc->zone))
+   if (!pageblock_pfn_to_page(block_start_pfn,
+   block_end_pfn, cc->zone))
break;
 
isolated = isolate_freepages_block(cc, _start_pfn,
@@ -864,18 +870,23 @@ unsigned long
 isolate_migratepages_range(struct compact_control *cc, unsigned long start_pfn,
unsigned long end_pfn)
 {
-   unsigned long pfn, block_end_pfn;
+   unsigned long pfn, block_start_pfn, block_end_pfn;
 
/* Scan block by block. First and last block may be incomplete */
pfn = start_pfn;
+   block_start_pfn = pfn & ~(pageblock_nr_pages - 1);
+   if (block_start_pfn < cc->zone->zone_start_pfn)
+   block_start_pfn = cc->zone->zone_start_pfn;
block_end_pfn = ALIGN(pfn + 1, pageblock_nr_pages);
 
for (; pfn < end_pfn; pfn = block_end_pfn,
+   block_start_pfn = block_end_pfn,
block_end_pfn += pageblock_nr_pages) {
 
block_end_pfn = min(block_end_pfn, end_pfn);
 
-   if (!pageblock_pfn_to_page(pfn, block_end_pfn, cc->zone))
+   if (!pageblock_pfn_to_page(block_start_pfn,
+   block_end_pfn, cc->zone))
continue;
 
pfn = isolate_migratepages_block(cc, pfn, block_end_pfn,
@@ -1104,7 +1115,9 @@ int sysctl_compact_unevictable_allowed __read_mostly = 1;
 static isolate_migrate_t isolate_migratepages(struct zone *zone,
struct compact_control *cc)
 {
-   unsigned long low_pfn, end_pfn;
+   unsigned long block_start_pfn;
+   unsigned long block_end_pfn;
+   unsigned long low_pfn;
unsigned long isolate_start_pfn;
struct page *page;
const isolate_mode_t isolate_mode =
@@ -1116,16 +1129,21 @@ static isolate_migrate_t isolate_migratepages(struct 
zone *zone,
 * initialized by compact_zone()
 */
low_pfn = cc->migrate_pfn;
+   block_start_pfn = cc->migrate_pfn & ~(pageblock_nr_pages - 1);
+   if (block_start_pfn < zone->zone_start_pfn)
+   block_start_pfn = zone->zone_start_pfn;
 
/* Only scan within a pageblock boundary */
-   end_pfn = ALIGN(low_pfn + 1, pageblock_nr_pages);
+   block_end_pfn = ALIGN(low_pfn + 1, pageblock_nr_pages);
 
/*
 * Iterate over whole pageblocks until we find the first suitable.
 * Do not cross the free scanner.
 */
-   for (; end_pfn <= cc->free_pfn;
-   low_pfn = end_pfn, end_pfn += pageblock_nr_pages) {
+   for (; block_end_pfn <= cc->free_pfn;
+   low_pfn = block_end_pfn,
+   block_start_pfn = block_end_pfn,
+  

[PATCH v2 1/3] mm/compaction: fix invalid free_pfn and compact_cached_free_pfn

2016-02-03 Thread Joonsoo Kim
free_pfn and compact_cached_free_pfn are the pointer that remember
restart position of freepage scanner. When they are reset or invalid,
we set them to zone_end_pfn because freepage scanner works in reverse
direction. But, because zone range is defined as [zone_start_pfn,
zone_end_pfn), zone_end_pfn is invalid to access. Therefore, we should
not store it to free_pfn and compact_cached_free_pfn. Instead, we need
to store zone_end_pfn - 1 to them. There is one more thing we should
consider. Freepage scanner scan reversely by pageblock unit. If free_pfn
and compact_cached_free_pfn are set to middle of pageblock, it regards
that sitiation as that it already scans front part of pageblock so we
lose opportunity to scan there. To fix-up, this patch do round_down()
to guarantee that reset position will be pageblock aligned.

Note that thanks to the current pageblock_pfn_to_page() implementation,
actual access to zone_end_pfn doesn't happen until now. But, following
patch will change pageblock_pfn_to_page() so this patch is needed
from now on.

Acked-by: David Rientjes 
Acked-by: Vlastimil Babka 
Signed-off-by: Joonsoo Kim 
---
 mm/compaction.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/mm/compaction.c b/mm/compaction.c
index 585de54..56fa321 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -200,7 +200,8 @@ static void reset_cached_positions(struct zone *zone)
 {
zone->compact_cached_migrate_pfn[0] = zone->zone_start_pfn;
zone->compact_cached_migrate_pfn[1] = zone->zone_start_pfn;
-   zone->compact_cached_free_pfn = zone_end_pfn(zone);
+   zone->compact_cached_free_pfn =
+   round_down(zone_end_pfn(zone) - 1, pageblock_nr_pages);
 }
 
 /*
@@ -1371,11 +1372,11 @@ static int compact_zone(struct zone *zone, struct 
compact_control *cc)
 */
cc->migrate_pfn = zone->compact_cached_migrate_pfn[sync];
cc->free_pfn = zone->compact_cached_free_pfn;
-   if (cc->free_pfn < start_pfn || cc->free_pfn > end_pfn) {
-   cc->free_pfn = end_pfn & ~(pageblock_nr_pages-1);
+   if (cc->free_pfn < start_pfn || cc->free_pfn >= end_pfn) {
+   cc->free_pfn = round_down(end_pfn - 1, pageblock_nr_pages);
zone->compact_cached_free_pfn = cc->free_pfn;
}
-   if (cc->migrate_pfn < start_pfn || cc->migrate_pfn > end_pfn) {
+   if (cc->migrate_pfn < start_pfn || cc->migrate_pfn >= end_pfn) {
cc->migrate_pfn = start_pfn;
zone->compact_cached_migrate_pfn[0] = cc->migrate_pfn;
zone->compact_cached_migrate_pfn[1] = cc->migrate_pfn;
-- 
1.9.1



[PATCH] mm/slub: support left red zone

2016-02-03 Thread Joonsoo Kim
SLUB already has red zone debugging feature. But, it is only positioned
at the end of object(aka right red zone) so it cannot catch left oob.
Although current object's right red zone acts as left red zone of
previous object, first object in a slab cannot take advantage of
this effect. This patch explicitly add left red zone to each objects
to detect left oob more precisely.

Signed-off-by: Joonsoo Kim 
---
 include/linux/slub_def.h |   1 +
 mm/slub.c| 158 ++-
 2 files changed, 115 insertions(+), 44 deletions(-)

diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
index b7e57927..a33869b 100644
--- a/include/linux/slub_def.h
+++ b/include/linux/slub_def.h
@@ -77,6 +77,7 @@ struct kmem_cache {
int refcount;   /* Refcount for slab cache destroy */
void (*ctor)(void *);
int inuse;  /* Offset to metadata */
+   int red_left_pad;   /* Left redzone padding size */
int align;  /* Alignment */
int reserved;   /* Reserved bytes at the end of slabs */
const char *name;   /* Name (only for display!) */
diff --git a/mm/slub.c b/mm/slub.c
index 7b5a965..7216769 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -39,6 +39,10 @@
 
 #include "internal.h"
 
+#ifdef CONFIG_KASAN
+#include "kasan/kasan.h"
+#endif
+
 /*
  * Lock order:
  *   1. slab_mutex (Global Mutex)
@@ -124,6 +128,14 @@ static inline int kmem_cache_debug(struct kmem_cache *s)
 #endif
 }
 
+static inline void *fixup_red_left(struct kmem_cache *s, void *p)
+{
+   if (kmem_cache_debug(s) && s->flags & SLAB_RED_ZONE)
+   p += s->red_left_pad;
+
+   return p;
+}
+
 static inline bool kmem_cache_has_cpu_partial(struct kmem_cache *s)
 {
 #ifdef CONFIG_SLUB_CPU_PARTIAL
@@ -224,24 +236,6 @@ static inline void stat(const struct kmem_cache *s, enum 
stat_item si)
  * Core slab cache functions
  ***/
 
-/* Verify that a pointer has an address that is valid within a slab page */
-static inline int check_valid_pointer(struct kmem_cache *s,
-   struct page *page, const void *object)
-{
-   void *base;
-
-   if (!object)
-   return 1;
-
-   base = page_address(page);
-   if (object < base || object >= base + page->objects * s->size ||
-   (object - base) % s->size) {
-   return 0;
-   }
-
-   return 1;
-}
-
 static inline void *get_freepointer(struct kmem_cache *s, void *object)
 {
return *(void **)(object + s->offset);
@@ -435,6 +429,22 @@ static void get_map(struct kmem_cache *s, struct page 
*page, unsigned long *map)
set_bit(slab_index(p, s, addr), map);
 }
 
+static inline int size_from_object(struct kmem_cache *s)
+{
+   if (s->flags & SLAB_RED_ZONE)
+   return s->size - s->red_left_pad;
+
+   return s->size;
+}
+
+static inline void *restore_red_left(struct kmem_cache *s, void *p)
+{
+   if (s->flags & SLAB_RED_ZONE)
+   p -= s->red_left_pad;
+
+   return p;
+}
+
 /*
  * Debug settings:
  */
@@ -468,6 +478,26 @@ static inline void metadata_access_disable(void)
 /*
  * Object debugging
  */
+
+/* Verify that a pointer has an address that is valid within a slab page */
+static inline int check_valid_pointer(struct kmem_cache *s,
+   struct page *page, void *object)
+{
+   void *base;
+
+   if (!object)
+   return 1;
+
+   base = page_address(page);
+   object = restore_red_left(s, object);
+   if (object < base || object >= base + page->objects * s->size ||
+   (object - base) % s->size) {
+   return 0;
+   }
+
+   return 1;
+}
+
 static void print_section(char *text, u8 *addr, unsigned int length)
 {
metadata_access_enable();
@@ -607,7 +637,9 @@ static void print_trailer(struct kmem_cache *s, struct page 
*page, u8 *p)
pr_err("INFO: Object 0x%p @offset=%tu fp=0x%p\n\n",
   p, p - addr, get_freepointer(s, p));
 
-   if (p > addr + 16)
+   if (s->flags & SLAB_RED_ZONE)
+   print_section("Redzone ", p - s->red_left_pad, s->red_left_pad);
+   else if (p > addr + 16)
print_section("Bytes b4 ", p - 16, 16);
 
print_section("Object ", p, min_t(unsigned long, s->object_size,
@@ -624,9 +656,9 @@ static void print_trailer(struct kmem_cache *s, struct page 
*page, u8 *p)
if (s->flags & SLAB_STORE_USER)
off += 2 * sizeof(struct track);
 
-   if (off != s->size)
+   if (off != size_from_object(s))
/* Beginning of the filler is the free pointer */
-   print_section("Padding ", p + off, s->size - off);
+   print_section("Padding ", p + off, size_from_object(s) - off);
 
dump_stack();
 }
@@ -656,6 +688,9 @@ static void 

Re: [PATCH] mmc: dw_mmc-rockchip: remove dw_mci_rockchip_pmops

2016-02-03 Thread Jaehoon Chung
Hi, Shawn.

On 02/03/2016 12:26 PM, Shawn Lin wrote:
> dw_mci_rockchip_pmops just copy-paste what dw_mci_pltfm_pmops
> have done. Let's remove it.

Yep, it's possible to remove.
I'm not sure but i want to know there is no plan to add the specific code of 
rockchip in suspend/resume.
Could you check this?

Best Regards,
Jaehoon Chung

> 
> Signed-off-by: Shawn Lin 
> ---
> 
>  drivers/mmc/host/dw_mmc-rockchip.c | 22 +-
>  1 file changed, 1 insertion(+), 21 deletions(-)
> 
> diff --git a/drivers/mmc/host/dw_mmc-rockchip.c 
> b/drivers/mmc/host/dw_mmc-rockchip.c
> index d9c92f3..3438ab3 100644
> --- a/drivers/mmc/host/dw_mmc-rockchip.c
> +++ b/drivers/mmc/host/dw_mmc-rockchip.c
> @@ -276,33 +276,13 @@ static int dw_mci_rockchip_probe(struct platform_device 
> *pdev)
>   return dw_mci_pltfm_register(pdev, drv_data);
>  }
>  
> -#ifdef CONFIG_PM_SLEEP
> -static int dw_mci_rockchip_suspend(struct device *dev)
> -{
> - struct dw_mci *host = dev_get_drvdata(dev);
> -
> - return dw_mci_suspend(host);
> -}
> -
> -static int dw_mci_rockchip_resume(struct device *dev)
> -{
> - struct dw_mci *host = dev_get_drvdata(dev);
> -
> - return dw_mci_resume(host);
> -}
> -#endif /* CONFIG_PM_SLEEP */
> -
> -static SIMPLE_DEV_PM_OPS(dw_mci_rockchip_pmops,
> -  dw_mci_rockchip_suspend,
> -  dw_mci_rockchip_resume);
> -
>  static struct platform_driver dw_mci_rockchip_pltfm_driver = {
>   .probe  = dw_mci_rockchip_probe,
>   .remove = dw_mci_pltfm_remove,
>   .driver = {
>   .name   = "dwmmc_rockchip",
>   .of_match_table = dw_mci_rockchip_match,
> - .pm = _mci_rockchip_pmops,
> + .pm = _mci_pltfm_pmops,
>   },
>  };
>  
> 



Re: [PATCH 1/2] mmc: dw_mmc: remove unused EVENT_XFER_ERROR

2016-02-03 Thread Jaehoon Chung
Hi, Shawn.

On 02/03/2016 12:26 PM, Shawn Lin wrote:
> EVENT_XFER_ERROR isn't been used now, so we can
> remove it.

If you are ok, after changing the commit message, I will apply this.
Thanks!

Best Regards,
Jaehoon Chung

> 
> Signed-off-by: Shawn Lin 
> ---
> 
>  include/linux/mmc/dw_mmc.h | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/include/linux/mmc/dw_mmc.h b/include/linux/mmc/dw_mmc.h
> index 89df7ab..b29e06e 100644
> --- a/include/linux/mmc/dw_mmc.h
> +++ b/include/linux/mmc/dw_mmc.h
> @@ -36,7 +36,6 @@ enum {
>   EVENT_XFER_COMPLETE,
>   EVENT_DATA_COMPLETE,
>   EVENT_DATA_ERROR,
> - EVENT_XFER_ERROR
>  };
>  
>  struct mmc_data;
> 



Re: [PATCH v2] mmc: dw_mmc: fix num_slots setting

2016-02-03 Thread Jaehoon Chung
Hi, Shawn.

On 02/02/2016 03:11 PM, Shawn Lin wrote:
> This patch make num_slots to 1 if pdata->num_slot is not
> defined. Meanwhile, we need to make sure num_slots should
> not larger that the supported slots

Thanks! I will apply this.

Best Regards,
Jaehoon Chung

> 
> Signed-off-by: Shawn Lin 
> 
> ---
> 
> Changes in v2:
> - remove default num-slots setting from dw_mci_parse_dt
> 
>  drivers/mmc/host/dw_mmc.c | 23 ++-
>  1 file changed, 10 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
> index 7128351..9696b77 100644
> --- a/drivers/mmc/host/dw_mmc.c
> +++ b/drivers/mmc/host/dw_mmc.c
> @@ -2864,12 +2864,7 @@ static struct dw_mci_board *dw_mci_parse_dt(struct 
> dw_mci *host)
>   return ERR_PTR(-ENOMEM);
>  
>   /* find out number of slots supported */
> - if (of_property_read_u32(dev->of_node, "num-slots",
> - >num_slots)) {
> - dev_info(dev,
> -  "num-slots property not found, assuming 1 slot is 
> available\n");
> - pdata->num_slots = 1;
> - }
> + of_property_read_u32(np, "num-slots", >num_slots);
>  
>   /* get quirks */
>   for (idx = 0; idx < ARRAY_SIZE(of_quirks); idx++)
> @@ -2949,12 +2944,6 @@ int dw_mci_probe(struct dw_mci *host)
>   }
>   }
>  
> - if (host->pdata->num_slots < 1) {
> - dev_err(host->dev,
> - "Platform data must supply num_slots.\n");
> - return -ENODEV;
> - }
> -
>   host->biu_clk = devm_clk_get(host->dev, "biu");
>   if (IS_ERR(host->biu_clk)) {
>   dev_dbg(host->dev, "biu clock not available\n");
> @@ -3111,7 +3100,15 @@ int dw_mci_probe(struct dw_mci *host)
>   if (host->pdata->num_slots)
>   host->num_slots = host->pdata->num_slots;
>   else
> - host->num_slots = SDMMC_GET_SLOT_NUM(mci_readl(host, HCON));
> + host->num_slots = 1;
> +
> + if (host->num_slots < 1 ||
> + host->num_slots > SDMMC_GET_SLOT_NUM(mci_readl(host, HCON))) {
> + dev_err(host->dev,
> + "Platform data must supply correct num_slots.\n");
> + ret = -ENODEV;
> + goto err_clk_ciu;
> + }
>  
>   /*
>* Enable interrupts for command done, data over, data empty,
> 



Re: [PATCH 04/14] clk: sunxi: add ahb1 clock for A83T

2016-02-03 Thread Vishnu Patekar
Hello Maxime,


On Tue, Feb 2, 2016 at 9:17 PM, Maxime Ripard
 wrote:
> Hi,
>
> On Sun, Jan 31, 2016 at 09:20:56AM +0800, Vishnu Patekar wrote:
>> AHB1 on A83T is similar to ahb1 on A31, except parents are different.
>> clock index 0b1x is PLL6.
>>
>> Signed-off-by: Vishnu Patekar 
>
> If the clock is the same but the parents are different, then we don't
> need to duplicate all the logic. Simply add the number of parents to
> mux_data, and you're all set.

Problem here is: parent 0b10 for A31 ahb1 is AXI, 0b11 is pll6/pre_div.
0b10 and 0b11 is pll6/pre_div.
So, just adding number of parents to mux_data will not solve problem.

Regards,
Vishnu
>
> Maxime
>
> --
> Maxime Ripard, Free Electrons
> Embedded Linux, Kernel and Android engineering
> http://free-electrons.com


Re: [PATCH 2/4] mmc: dw_mmc: add setup_clk for init hook

2016-02-03 Thread Jaehoon Chung
Hi, Shawn.

On 01/28/2016 10:31 AM, Shawn Lin wrote:
> We add this new argument into init hook for
> variant drivers to decide whether to do clock
> related stuff inside the hook.
> 
> Signed-off-by: Shawn Lin 
> ---
> 
>  drivers/mmc/host/dw_mmc-exynos.c   | 4 ++--
>  drivers/mmc/host/dw_mmc-rockchip.c | 2 +-
>  drivers/mmc/host/dw_mmc.c  | 2 +-
>  drivers/mmc/host/dw_mmc.h  | 2 +-
>  4 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/mmc/host/dw_mmc-exynos.c 
> b/drivers/mmc/host/dw_mmc-exynos.c
> index 3a7e835..edaa117 100644
> --- a/drivers/mmc/host/dw_mmc-exynos.c
> +++ b/drivers/mmc/host/dw_mmc-exynos.c
> @@ -91,7 +91,7 @@ static inline u8 dw_mci_exynos_get_ciu_div(struct dw_mci 
> *host)
>   return SDMMC_CLKSEL_GET_DIV(mci_readl(host, CLKSEL)) + 1;
>  }
>  
> -static int dw_mci_exynos_priv_init(struct dw_mci *host)
> +static int dw_mci_exynos_priv_init(struct dw_mci *host, bool setup_clk)
>  {

"bool setup_clk" is made because of exynos SoC, right?
Hmm. I'm checking how we can control without "setup_clk". Waiting for this.

Thanks for removing the hooks. :)

Best Regards,
Jaehoon Chung

>   struct dw_mci_exynos_priv_data *priv = host->priv;
>  
> @@ -159,7 +159,7 @@ static int dw_mci_exynos_resume(struct device *dev)
>  {
>   struct dw_mci *host = dev_get_drvdata(dev);
>  
> - dw_mci_exynos_priv_init(host);
> + dw_mci_exynos_priv_init(host, false);
>   return dw_mci_resume(host);
>  }
>  
> diff --git a/drivers/mmc/host/dw_mmc-rockchip.c 
> b/drivers/mmc/host/dw_mmc-rockchip.c
> index 9934503..885c801 100644
> --- a/drivers/mmc/host/dw_mmc-rockchip.c
> +++ b/drivers/mmc/host/dw_mmc-rockchip.c
> @@ -221,7 +221,7 @@ static int dw_mci_rk3288_parse_dt(struct dw_mci *host)
>   return 0;
>  }
>  
> -static int dw_mci_rockchip_init(struct dw_mci *host)
> +static int dw_mci_rockchip_init(struct dw_mci *host, bool setup_clk)
>  {
>   /* It is slot 8 on Rockchip SoCs */
>   host->sdio_id0 = 8;
> diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
> index 7128351..1d27a2b 100644
> --- a/drivers/mmc/host/dw_mmc.c
> +++ b/drivers/mmc/host/dw_mmc.c
> @@ -2995,7 +2995,7 @@ int dw_mci_probe(struct dw_mci *host)
>   }
>  
>   if (drv_data && drv_data->init) {
> - ret = drv_data->init(host);
> + ret = drv_data->init(host, true);
>   if (ret) {
>   dev_err(host->dev,
>   "implementation specific init failed\n");
> diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
> index f695b58..1a9492e 100644
> --- a/drivers/mmc/host/dw_mmc.h
> +++ b/drivers/mmc/host/dw_mmc.h
> @@ -285,7 +285,7 @@ struct dw_mci_slot {
>   */
>  struct dw_mci_drv_data {
>   unsigned long   *caps;
> - int (*init)(struct dw_mci *host);
> + int (*init)(struct dw_mci *host, bool setup_clk);
>   int (*setup_clock)(struct dw_mci *host);
>   void(*prepare_command)(struct dw_mci *host, u32 *cmdr);
>   void(*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
> 



Re: [PATCH] mm, hugetlb: don't require CMA for runtime gigantic pages

2016-02-03 Thread Joonsoo Kim
On Wed, Feb 03, 2016 at 06:50:11PM +0100, Vlastimil Babka wrote:
> Commit 944d9fec8d7a ("hugetlb: add support for gigantic page allocation at
> runtime") has added the runtime gigantic page allocation via
> alloc_contig_range(), making this support available only when CONFIG_CMA is
> enabled. Because it doesn't depend on MIGRATE_CMA pageblocks and the
> associated infrastructure, it is possible with few simple adjustments to
> require only CONFIG_MEMORY_ISOLATION instead of full CONFIG_CMA.
> 
> After this patch, alloc_contig_range() and related functions are available
> and used for gigantic pages with just CONFIG_MEMORY_ISOLATION enabled. Note
> CONFIG_CMA selects CONFIG_MEMORY_ISOLATION. This allows supporting runtime
> gigantic pages without the CMA-specific checks in page allocator fastpaths.

You need to set CONFIG_COMPACTION or CONFIG_CMA to use
isolate_migratepages_range() and others in alloc_contig_range().

Thanks.



[PATCH 2/5] mm/slub: query dynamic DEBUG_PAGEALLOC setting

2016-02-03 Thread Joonsoo Kim
We can disable debug_pagealloc processing even if the code is complied
with CONFIG_DEBUG_PAGEALLOC. This patch changes the code to query
whether it is enabled or not in runtime.

Signed-off-by: Joonsoo Kim 
---
 mm/slub.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index 7d4da68..7b5a965 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -256,11 +256,12 @@ static inline void *get_freepointer_safe(struct 
kmem_cache *s, void *object)
 {
void *p;
 
-#ifdef CONFIG_DEBUG_PAGEALLOC
-   probe_kernel_read(, (void **)(object + s->offset), sizeof(p));
-#else
-   p = get_freepointer(s, object);
-#endif
+   if (debug_pagealloc_enabled()) {
+   probe_kernel_read(,
+   (void **)(object + s->offset), sizeof(p));
+   } else
+   p = get_freepointer(s, object);
+
return p;
 }
 
-- 
1.9.1



[PATCH 1/5] mm/vmalloc: query dynamic DEBUG_PAGEALLOC setting

2016-02-03 Thread Joonsoo Kim
We can disable debug_pagealloc processing even if the code is complied
with CONFIG_DEBUG_PAGEALLOC. This patch changes the code to query
whether it is enabled or not in runtime.

Signed-off-by: Joonsoo Kim 
---
 mm/vmalloc.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index fb42a5b..e0e51bd 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -543,10 +543,10 @@ static void vmap_debug_free_range(unsigned long start, 
unsigned long end)
 * debugging doesn't do a broadcast TLB flush so it is a lot
 * faster).
 */
-#ifdef CONFIG_DEBUG_PAGEALLOC
-   vunmap_page_range(start, end);
-   flush_tlb_kernel_range(start, end);
-#endif
+   if (debug_pagealloc_enabled()) {
+   vunmap_page_range(start, end);
+   flush_tlb_kernel_range(start, end);
+   }
 }
 
 /*
-- 
1.9.1



[PATCH 3/5] sound: query dynamic DEBUG_PAGEALLOC setting

2016-02-03 Thread Joonsoo Kim
We can disable debug_pagealloc processing even if the code is complied
with CONFIG_DEBUG_PAGEALLOC. This patch changes the code to query
whether it is enabled or not in runtime.

Signed-off-by: Joonsoo Kim 
---
 sound/drivers/pcsp/pcsp.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/sound/drivers/pcsp/pcsp.c b/sound/drivers/pcsp/pcsp.c
index 27e25bb..72e2d00 100644
--- a/sound/drivers/pcsp/pcsp.c
+++ b/sound/drivers/pcsp/pcsp.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "pcsp_input.h"
 #include "pcsp.h"
 
@@ -148,11 +149,11 @@ static int alsa_card_pcsp_init(struct device *dev)
return err;
}
 
-#ifdef CONFIG_DEBUG_PAGEALLOC
/* Well, CONFIG_DEBUG_PAGEALLOC makes the sound horrible. Lets alert */
-   printk(KERN_WARNING "PCSP: CONFIG_DEBUG_PAGEALLOC is enabled, "
-  "which may make the sound noisy.\n");
-#endif
+   if (debug_pagealloc_enabled()) {
+   printk(KERN_WARNING "PCSP: CONFIG_DEBUG_PAGEALLOC is enabled, "
+  "which may make the sound noisy.\n");
+   }
 
return 0;
 }
-- 
1.9.1



[PATCH 5/5] tile: query dynamic DEBUG_PAGEALLOC setting

2016-02-03 Thread Joonsoo Kim
We can disable debug_pagealloc processing even if the code is complied
with CONFIG_DEBUG_PAGEALLOC. This patch changes the code to query
whether it is enabled or not in runtime.

Signed-off-by: Joonsoo Kim 
---
 arch/tile/mm/init.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/tile/mm/init.c b/arch/tile/mm/init.c
index d4e1fc4..a0582b7 100644
--- a/arch/tile/mm/init.c
+++ b/arch/tile/mm/init.c
@@ -896,17 +896,15 @@ void __init pgtable_cache_init(void)
panic("pgtable_cache_init(): Cannot create pgd cache");
 }
 
-#ifdef CONFIG_DEBUG_PAGEALLOC
-static long __write_once initfree;
-#else
 static long __write_once initfree = 1;
-#endif
+static bool __write_once set_initfree_done;
 
 /* Select whether to free (1) or mark unusable (0) the __init pages. */
 static int __init set_initfree(char *str)
 {
long val;
if (kstrtol(str, 0, ) == 0) {
+   set_initfree_done = true;
initfree = val;
pr_info("initfree: %s free init pages\n",
initfree ? "will" : "won't");
@@ -919,6 +917,11 @@ static void free_init_pages(char *what, unsigned long 
begin, unsigned long end)
 {
unsigned long addr = (unsigned long) begin;
 
+   /* Prefer user request first */
+   if (!set_initfree_done) {
+   if (debug_pagealloc_enabled())
+   initfree = 0;
+   }
if (kdata_huge && !initfree) {
pr_warn("Warning: ignoring initfree=0: incompatible with 
kdata=huge\n");
initfree = 1;
-- 
1.9.1



[PATCH 4/5] powerpc: query dynamic DEBUG_PAGEALLOC setting

2016-02-03 Thread Joonsoo Kim
We can disable debug_pagealloc processing even if the code is complied
with CONFIG_DEBUG_PAGEALLOC. This patch changes the code to query
whether it is enabled or not in runtime.

Signed-off-by: Joonsoo Kim 
---
 arch/powerpc/kernel/traps.c |  5 ++---
 arch/powerpc/mm/hash_utils_64.c | 40 
 arch/powerpc/mm/init_32.c   |  8 
 3 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index b6becc7..33c47fc 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -203,9 +203,8 @@ static int __kprobes __die(const char *str, struct pt_regs 
*regs, long err)
 #ifdef CONFIG_SMP
printk("SMP NR_CPUS=%d ", NR_CPUS);
 #endif
-#ifdef CONFIG_DEBUG_PAGEALLOC
-   printk("DEBUG_PAGEALLOC ");
-#endif
+   if (debug_pagealloc_enabled())
+   printk("DEBUG_PAGEALLOC ");
 #ifdef CONFIG_NUMA
printk("NUMA ");
 #endif
diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c
index ba59d59..03a622b 100644
--- a/arch/powerpc/mm/hash_utils_64.c
+++ b/arch/powerpc/mm/hash_utils_64.c
@@ -255,10 +255,10 @@ int htab_bolt_mapping(unsigned long vstart, unsigned long 
vend,
 
if (ret < 0)
break;
-#ifdef CONFIG_DEBUG_PAGEALLOC
-   if ((paddr >> PAGE_SHIFT) < linear_map_hash_count)
+
+   if (debug_pagealloc_enabled() &&
+   (paddr >> PAGE_SHIFT) < linear_map_hash_count)
linear_map_hash_slots[paddr >> PAGE_SHIFT] = ret | 0x80;
-#endif /* CONFIG_DEBUG_PAGEALLOC */
}
return ret < 0 ? ret : 0;
 }
@@ -512,17 +512,17 @@ static void __init htab_init_page_sizes(void)
if (mmu_has_feature(MMU_FTR_16M_PAGE))
memcpy(mmu_psize_defs, mmu_psize_defaults_gp,
   sizeof(mmu_psize_defaults_gp));
- found:
-#ifndef CONFIG_DEBUG_PAGEALLOC
-   /*
-* Pick a size for the linear mapping. Currently, we only support
-* 16M, 1M and 4K which is the default
-*/
-   if (mmu_psize_defs[MMU_PAGE_16M].shift)
-   mmu_linear_psize = MMU_PAGE_16M;
-   else if (mmu_psize_defs[MMU_PAGE_1M].shift)
-   mmu_linear_psize = MMU_PAGE_1M;
-#endif /* CONFIG_DEBUG_PAGEALLOC */
+found:
+   if (!debug_pagealloc_enabled()) {
+   /*
+* Pick a size for the linear mapping. Currently, we only
+* support 16M, 1M and 4K which is the default
+*/
+   if (mmu_psize_defs[MMU_PAGE_16M].shift)
+   mmu_linear_psize = MMU_PAGE_16M;
+   else if (mmu_psize_defs[MMU_PAGE_1M].shift)
+   mmu_linear_psize = MMU_PAGE_1M;
+   }
 
 #ifdef CONFIG_PPC_64K_PAGES
/*
@@ -720,12 +720,12 @@ static void __init htab_initialize(void)
 
prot = pgprot_val(PAGE_KERNEL);
 
-#ifdef CONFIG_DEBUG_PAGEALLOC
-   linear_map_hash_count = memblock_end_of_DRAM() >> PAGE_SHIFT;
-   linear_map_hash_slots = __va(memblock_alloc_base(linear_map_hash_count,
-   1, ppc64_rma_size));
-   memset(linear_map_hash_slots, 0, linear_map_hash_count);
-#endif /* CONFIG_DEBUG_PAGEALLOC */
+   if (debug_pagealloc_enabled()) {
+   linear_map_hash_count = memblock_end_of_DRAM() >> PAGE_SHIFT;
+   linear_map_hash_slots = __va(memblock_alloc_base(
+   linear_map_hash_count, 1, ppc64_rma_size));
+   memset(linear_map_hash_slots, 0, linear_map_hash_count);
+   }
 
/* On U3 based machines, we need to reserve the DART area and
 * _NOT_ map it to avoid cache paradoxes as it's remapped non
diff --git a/arch/powerpc/mm/init_32.c b/arch/powerpc/mm/init_32.c
index a10be66..c2b7716 100644
--- a/arch/powerpc/mm/init_32.c
+++ b/arch/powerpc/mm/init_32.c
@@ -112,10 +112,10 @@ void __init MMU_setup(void)
if (strstr(boot_command_line, "noltlbs")) {
__map_without_ltlbs = 1;
}
-#ifdef CONFIG_DEBUG_PAGEALLOC
-   __map_without_bats = 1;
-   __map_without_ltlbs = 1;
-#endif
+   if (debug_pagealloc_enabled()) {
+   __map_without_bats = 1;
+   __map_without_ltlbs = 1;
+   }
 }
 
 /*
-- 
1.9.1



[PATCH 0/5] follow-up "Optimize CONFIG_DEBUG_PAGEALLOC"

2016-02-03 Thread Joonsoo Kim
As CONFIG_DEBUG_PAGEALLOC can be enabled/disabled via kernel
parameters we can optimize some cases by checking the enablement
state.

This is follow-up work for Christian's Optimize CONFIG_DEBUG_PAGEALLOC.

https://lkml.org/lkml/2016/1/27/194

I can't test patches for sound, power and tile,
so please review them, maintainers. :)

Remaining work is to make sparc to be aware of this but it looks
not easy for me so I skip that in this series.

It would be the best that these paches are routed through Andrew's tree,
because there is a dependency to MM.

Thanks.

Joonsoo Kim (5):
  mm/vmalloc: query dynamic DEBUG_PAGEALLOC setting
  mm/slub: query dynamic DEBUG_PAGEALLOC setting
  sound: query dynamic DEBUG_PAGEALLOC setting
  powerpc: query dynamic DEBUG_PAGEALLOC setting
  tile: query dynamic DEBUG_PAGEALLOC setting

 arch/powerpc/kernel/traps.c |  5 ++---
 arch/powerpc/mm/hash_utils_64.c | 40 
 arch/powerpc/mm/init_32.c   |  8 
 arch/tile/mm/init.c | 11 +++
 mm/slub.c   | 11 ++-
 mm/vmalloc.c|  8 
 sound/drivers/pcsp/pcsp.c   |  9 +
 7 files changed, 48 insertions(+), 44 deletions(-)

-- 
1.9.1



Re: [PATCH] psmouse: added BYD touchpad driver

2016-02-03 Thread Richard Pospesel

Rebased patch against 98ee377144935857d8ad5d7d70cdab1da4ede32e:

---
diff --git a/drivers/input/mouse/byd.c b/drivers/input/mouse/byd.c
index 9425e0f..f213a08 100644
--- a/drivers/input/mouse/byd.c
+++ b/drivers/input/mouse/byd.c
@@ -2,93 +2,276 @@
  * BYD TouchPad PS/2 mouse driver
  *
  * Copyright (C) 2015 Chris Diamand 
+ * Copyright (C) 2015 Richard Pospesel
+ * Copyright (C) 2015 Tai Chi Minh Ralph Eastwood
+ * Copyright (C) 2015 Martin Wimpress
+ * Copyright (C) 2015 Jay Kuri
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 as 
published by

  * the Free Software Foundation.
+ *
+ * Protocol of BYD Touch Pad reverse-engineered from windows driver:
+ * filename:  "byd touchpad driver - win7, 8, 8.1 - 2.4.1.102.zip"
+ * md5:   0d5e4660b98fca9587a0df212fca3048
+ * sha1:  97a0eca8edc482bf9d08ab9509084a514dad4c4b
+ * datasheet: http://bydit.com/userfiles/file/BTP10463-XXX.pdf
  */

 #include 
 #include 
 #include 
 #include 
+#include 

 #include "psmouse.h"
 #include "byd.h"

-#define PS2_Y_OVERFLOW BIT_MASK(7)
-#define PS2_X_OVERFLOW BIT_MASK(6)
-#define PS2_Y_SIGN BIT_MASK(5)
-#define PS2_X_SIGN BIT_MASK(4)
-#define PS2_ALWAYS_1   BIT_MASK(3)
-#define PS2_MIDDLE BIT_MASK(2)
-#define PS2_RIGHT  BIT_MASK(1)
-#define PS2_LEFT   BIT_MASK(0)
+/* PS2 Bits */
+#define PS2_Y_OVERFLOW BIT_MASK(7)
+#define PS2_X_OVERFLOW BIT_MASK(6)
+#define PS2_Y_SIGN BIT_MASK(5)
+#define PS2_X_SIGN BIT_MASK(4)
+#define PS2_ALWAYS_1   BIT_MASK(3)
+#define PS2_MIDDLE BIT_MASK(2)
+#define PS2_RIGHT  BIT_MASK(1)
+#define PS2_LEFT   BIT_MASK(0)

 /*
- * The touchpad reports gestures in the last byte of each packet. It 
can take

- * any of the following values:
+ * BYD pad constants
+ *
+ * True device resolution is unknown, however experiments show the
+ * resolution is about 111 units/mm.
+ * Absolute coordinate packets are in the range 0-255 for both X and Y
+ * we pick ABS_X/ABS_Y dimensions which are multiples of 256 and in
+ * the right ballpark given the touchpad's physical dimensions and estimate
+ * resolution per spec sheet, device active area dimensions are
+ * 101.6 x 60.1 mm.
  */
+#define BYD_CONST_PAD_WIDTH 11264
+#define BYD_CONST_PAD_HEIGHT 6656
+#define BYD_CONST_PAD_RESOLUTION 111

-/* One-finger scrolling in one of the edge scroll zones. */
-#define BYD_SCROLLUP   0xCA
-#define BYD_SCROLLDOWN 0x36
-#define BYD_SCROLLLEFT 0xCB
-#define BYD_SCROLLRIGHT0x35
-/* Two-finger scrolling. */
-#define BYD_2DOWN  0x2B
-#define BYD_2UP0xD5
-#define BYD_2LEFT  0xD6
-#define BYD_2RIGHT 0x2A
-/* Pinching in or out. */
-#define BYD_ZOOMOUT0xD8
-#define BYD_ZOOMIN 0x28
-/* Three-finger swipe. */
-#define BYD_3UP0xD3
-#define BYD_3DOWN  0x2D
-#define BYD_3LEFT  0xD4
-#define BYD_3RIGHT 0x2C
-/* Four-finger swipe. */
-#define BYD_4UP0xCD
-#define BYD_4DOWN  0x33
-
-int byd_detect(struct psmouse *psmouse, bool set_properties)
-{
-   struct ps2dev *ps2dev = >ps2dev;
-   unsigned char param[4];
+/* BYD commands reverse engineered from windows driver */

-   param[0] = 0x03;
-   param[1] = 0x00;
-   param[2] = 0x00;
-   param[3] = 0x00;
-
-   if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES))
-   return -1;
-   if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES))
-   return -1;
-   if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES))
-   return -1;
-   if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES))
-   return -1;
-   if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
-   return -1;
+/*
+ * Swipe gesture from off-pad to on-pad
+ *  0 : disable
+ *  1 : enable
+ */
+#define BYD_CMD_SET_OFFSCREEN_SWIPE0x10cc
+/*
+ * Tap and drag delay time
+ *  0 : disable
+ *  1 - 8 : least to most delay
+ */
+#define BYD_CMD_SET_TAP_DRAG_DELAY_TIME0x10cf
+/*
+ * Physical buttons function mapping
+ *  0 : enable
+ *  4 : normal
+ *  5 : left button custom command
+ *  6 : right button custom command
+ *  8 : disable
+ */
+#define BYD_CMD_SET_PHYSICAL_BUTTONS   0x10d0
+/*
+ * Absolute mode (1 byte X/Y resolution)
+ *  0 : disable
+ *  2 : enable
+ */
+#define BYD_CMD_SET_ABSOLUTE_MODE  0x10d1
+/*
+ * Two finger scrolling
+ *  1 : vertical
+ *  2 : horizontal
+ *  3 : vertical + horizontal
+ *  4 : disable
+ */
+#define BYD_CMD_SET_TWO_FINGER_SCROLL  0x10d2
+/*
+ * Handedness
+ *  1 : right handed
+ *  2 : left handed
+ */
+#define BYD_CMD_SET_HANDEDNESS 0x10d3
+/*
+ * Tap to click
+ *  1 : enable
+ *  2 : disable
+ */
+#define BYD_CMD_SET_TAP0x10d4
+/*
+ * Tap and drag
+ *  1 : tap and hold to drag
+ *  2 : tap and 

Re: [PATCH V2 0/7] cpufreq: governors: Fix ABBA lockups

2016-02-03 Thread Viresh Kumar
On 04-02-16, 00:50, Rafael J. Wysocki wrote:
> On Thu, Feb 4, 2016 at 12:31 AM, Shilpa Bhat  wrote:
> > Sorry for the delayed report. But I see the below backtrace on Power8 box. 
> > It
> > has 4 chips with 128 cpus.

Honestly, I wasn't expecting you to test this stuff, but I really
appreciate you doing that.

Thanks a lot ..

> > [  906.765768]  Possible unsafe locking scenario:
> >
> > [  906.765880]CPU0CPU1
> > [  906.765969]

This race scenario is perhaps incomplete and difficult to understand
without below lines:

  Governor's EXIT Update sampling rate from 
sysfs

  lock(s_active#91);

> > [  906.766058]   lock(od_dbs_cdata.mutex);
> > [  906.766170]lock(_data->mutex);
> > [  906.766304]lock(od_dbs_cdata.mutex);
> > [  906.766461]   lock(s_active#91);
> > [  906.766572]
> >  *** DEADLOCK ***
> 
> This is exactly right.  We've avoided one deadlock only to trip into
> another one.

As we discussed on IRC, we haven't introduced this deadlock with the
current series.  But this is what Juri has reported some days back,
while he tested linus/master on TC2.

> This happens because update_sampling_rate() acquires
> od_dbs_cdata.mutex which is held around cpufreq_governor_exit() by
> cpufreq_governor_dbs().
> 
> Worse yet, a deadlock can still happen without (the new)
> dbs_data->mutex, just between s_active and od_dbs_cdata.mutex if
> update_sampling_rate() runs in parallel with
> cpufreq_governor_dbs()->cpufreq_governor_exit() and the latter wins
> the race.
> 
> It looks like we need to drop the governor mutex before putting the
> kobject in cpufreq_governor_exit().

That wouldn't be trivial to implement as we discussed.

Okay, here is a proposal for the current series and the series's you
have post Rafael:

- Firstly, I would like to clarify that I don't have any issues with
  rebasing on top of your series, it should be easy enough.

- One thing is for sure that nothing from these 3 series's is getting
  merged in 4.5, as we aren't fixing the real issue Shilpa/Juril have
  reported.

- I think the first 4 patches here are just fine and don't need any
  updates. They actually do the right thing and makes code so much
  cleaner.

- So, can we apply the first 4 patches (which  you have already
  applied to bleeding-edge) now and do all work on top of that ?

Again, I can rebase if you merge your patches first, no issues at all
:)

-- 
viresh


RE: [PATCH V2 5/5] Microblaze: Modifying microblaze PCI subsytem to support generic Xilinx AXI PCIe Host Bridge IP driver

2016-02-03 Thread Bharat Kumar Gogada
> Subject: Re: [PATCH V2 5/5] Microblaze: Modifying microblaze PCI subsytem
> to support generic Xilinx AXI PCIe Host Bridge IP driver
> 
> [+cc Ben for real this time]
> 
> On Wed, Feb 03, 2016 at 10:32:07AM -0600, Bjorn Helgaas wrote:
> > [+cc Ben, pcibios_get_phb_of_node() question]
> >
> > On Tue, Jan 12, 2016 at 11:06:13PM +0530, Bharat Kumar Gogada wrote:
> > > This patch does required modifications to microblaze PCI subsystem,
> > > to work with generic driver (drivers/pci/host/pcie-xilinx.c) on
> > > Microblaze and Zynq.
> > >
> > > Signed-off-by: Bharat Kumar Gogada 
> > > Signed-off-by: Ravi Kiran Gummaluri  ...
> >
> > >  resource_size_t pcibios_align_resource(void *data, const struct resource
> *res,
> > >   resource_size_t size, resource_size_t align)  {
> > > - struct pci_dev *dev = data;
> > >   resource_size_t start = res->start;
> > >
> > > - if (res->flags & IORESOURCE_IO) {
> > > - if (skip_isa_ioresource_align(dev))
> > > - return start;
> > > - if (start & 0x300)
> > > - start = (start + 0x3ff) & ~0x3ff;
> > > - }
> > > -
> > >   return start;
> >
> > "return res->start;" is sufficient; no need for a temporary variable.
> >
Agreed will address in next patch.
> > >  }
> > >  EXPORT_SYMBOL(pcibios_align_resource);
> > >
> > > +int pcibios_add_device(struct pci_dev *dev) {
> > > + dev->irq = of_irq_parse_and_map_pci(dev, 0, 0);
> > > +
> > > + return 0;
> > > +}
> > > +EXPORT_SYMBOL(pcibios_add_device);
> > > +
> > >  /*
> > >   * Reparent resource children of pr that conflict with res
> > >   * under res, and make res replace those children.
> > > @@ -1335,9 +1308,21 @@ static void
> > > pcibios_setup_phb_resources(struct pci_controller *hose,
> > >
> > >  struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus)  {
> > > - struct pci_controller *hose = bus->sysdata;
> > > + struct device_node *np;
> > > +
> > > + for_each_node_by_type(np, "pci") {
> > > + const void *prop;
> > > + unsigned int bus_min;
> > > +
> > > + prop = of_get_property(np, "bus-range", NULL);
> > > + if (!prop)
> > > + continue;
> > > + bus_min = be32_to_cpup(prop);
> > > + if (bus->number == bus_min)
> > > + return np;
> > > + }
> > >
> > > - return of_node_get(hose->dn);
> > > + return NULL;
> >
> > Hmmm.  The old microblaze code ("return of_node_get(hose->dn);") is
> > basically the same as the mips and powerpc versions.  The new code is
> > basically the same as the x86 version.
> >
> > I like the generic weak version in drivers/pci/of.c because it doesn't
> > use any arch-specific data, and it looks like if we just set the
> > struct device.of_node members correctly, everything should Just Work.
> >
> > But Ben added both the generic and the x86 versions the same day, so
> > there must be some complication:
> >
> >   98d9f30c820d ("pci/of: Match PCI devices to OF nodes dynamically")
> >   3d5fe5a65af9 ("x86/devicetree: Use generic PCI <-> OF matching")
> >
> > So I guess my question is, why do we need a microblaze-specific
> > version at all?
> >
I did not notice the weak version in /pci/of.c, I have tested with weak version 
also and it is working.  We might not need this microblaze specific version, 
but will wait for ben's reply.  

Bharat


Re: [PATCH] clk: Deprecate CLK_IS_ROOT

2016-02-03 Thread Michael Turquette
Quoting Stephen Boyd (2016-02-02 17:42:13)
> We don't use CLK_IS_ROOT but in a few places in the common clk
> framework core. Let's replace those checks with a check for the
> number of parents a clk has instead of the flag, freeing up one
> flag for something else. We don't remove the flag yet so that
> things keep building, but we'll remove it once all drivers have
> removed their flag usage.
> 
> Signed-off-by: Stephen Boyd 

Looks good to me.

Regards,
Mike

> ---
> 
> A bunch of patches to remove CLK_IS_ROOT are coming...
> 
>  drivers/clk/clk.c| 6 +++---
>  include/linux/clk-provider.h | 2 +-
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index bb01ed6cc63e..cd8382c83f48 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -385,7 +385,7 @@ static unsigned long clk_core_get_rate_nolock(struct 
> clk_core *core)
>  
> ret = core->rate;
>  
> -   if (core->flags & CLK_IS_ROOT)
> +   if (!core->num_parents)
> goto out;
>  
> if (!core->parent)
> @@ -2351,7 +2351,7 @@ static int __clk_core_init(struct clk_core *core)
> /*
>  * Populate core->parent if parent has already been __clk_init'd.  If
>  * parent has not yet been __clk_init'd then place clk in the orphan
> -* list.  If clk has set the CLK_IS_ROOT flag then place it in the 
> root
> +* list.  If clk doesn't have any parents then place it in the root
>  * clk list.
>  *
>  * Every time a new clk is clk_init'd then we walk the list of orphan
> @@ -2362,7 +2362,7 @@ static int __clk_core_init(struct clk_core *core)
> hlist_add_head(>child_node,
> >parent->children);
> core->orphan = core->parent->orphan;
> -   } else if (core->flags & CLK_IS_ROOT) {
> +   } else if (!core->num_parents) {
> hlist_add_head(>child_node, _root_list);
> core->orphan = false;
> } else {
> diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
> index fabe5bedbba6..9c3a18c1a984 100644
> --- a/include/linux/clk-provider.h
> +++ b/include/linux/clk-provider.h
> @@ -25,7 +25,7 @@
>  #define CLK_SET_PARENT_GATEBIT(1) /* must be gated across re-parent */
>  #define CLK_SET_RATE_PARENTBIT(2) /* propagate rate change up one level 
> */
>  #define CLK_IGNORE_UNUSED  BIT(3) /* do not gate even if unused */
> -#define CLK_IS_ROOTBIT(4) /* root clk, has no parent */
> +#define CLK_IS_ROOTBIT(4) /* Deprecated: Don't use */
>  #define CLK_IS_BASIC   BIT(5) /* Basic clk, can't do a to_clk_foo() 
> */
>  #define CLK_GET_RATE_NOCACHE   BIT(6) /* do not use the cached clk rate */
>  #define CLK_SET_RATE_NO_REPARENT BIT(7) /* don't re-parent on rate change */
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 


RE: [PATCH RESEND] tcp_estats: ebpf hacks

2016-02-03 Thread Martin Lau
Please ignore. It is a mistake...

From: Martin KaFai Lau [ka...@fb.com]
Sent: Wednesday, February 03, 2016 9:39 PM
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar; Masami Hiramatsu; Steven Rostedt; Alexei Starovoitov; Josef 
Bacik; Kernel Team
Subject: [PATCH RESEND] tcp_estats: ebpf hacks

Signed-off-by: Martin KaFai Lau 
---
 kernel/trace/bpf_trace.c |  20 ++
 samples/Makefile |   2 +-
 samples/bpf/Makefile |  11 +-
 samples/bpf/bpf_helpers.h|   4 +
 samples/bpf/bpf_load.c   |  44 +++--
 samples/bpf/tcp_trace.h  |  51 +
 samples/bpf/tcp_trace_kern.c | 454 +++
 samples/bpf/tcp_trace_user.c | 115 +++
 tools/net/Makefile   |   6 +-
 9 files changed, 689 insertions(+), 18 deletions(-)
 create mode 100644 samples/bpf/tcp_trace.h
 create mode 100644 samples/bpf/tcp_trace_kern.c
 create mode 100644 samples/bpf/tcp_trace_user.c

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 47febbe..977702e 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -68,6 +68,7 @@ static u64 bpf_probe_read(u64 r1, u64 r2, u64 r3, u64 r4, u64 
r5)
void *unsafe_ptr = (void *) (long) r3;

return probe_kernel_read(dst, unsafe_ptr, size);
+   /* return __bpf_probe_read_hack(dst, unsafe_ptr, size); */
 }

 static const struct bpf_func_proto bpf_probe_read_proto = {
@@ -79,6 +80,25 @@ static const struct bpf_func_proto bpf_probe_read_proto = {
.arg3_type  = ARG_ANYTHING,
 };

+static u64 bpf_probe_read_u32(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
+{
+   u32 *dst = (u32 *) (long) r1;
+   int size = (int) r2;
+   u32 *unsafe_ptr = (void *) (long) r3;
+
+   *dst = *unsafe_ptr;
+   return probe_kernel_read(dst, unsafe_ptr, size);
+}
+
+static const struct bpf_func_proto bpf_probe_read_u32_proto = {
+   .func   = bpf_probe_read,
+   .gpl_only   = true,
+   .ret_type   = RET_VOID,
+   .arg1_type  = ARG_PTR_TO_STACK,
+   .arg2_type  = ARG_CONST_STACK_SIZE,
+   .arg3_type  = ARG_ANYTHING,
+};
+
 /*
  * limited trace_printk()
  * only %d %u %x %ld %lu %lx %lld %llu %llx %p %s conversion specifiers allowed
diff --git a/samples/Makefile b/samples/Makefile
index f00257b..fb87be5 100644
--- a/samples/Makefile
+++ b/samples/Makefile
@@ -1,4 +1,4 @@
 # Makefile for Linux samples code

 obj-$(CONFIG_SAMPLES)  += kobject/ kprobes/ trace_events/ livepatch/ \
-  hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/
+  hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/ 
bpf/
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 97e5243..02885ae 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -14,6 +14,7 @@ hostprogs-y += tracex4
 hostprogs-y += tracex5
 hostprogs-y += trace_output
 hostprogs-y += lathist
+hostprogs-y += tcp_trace

 test_verifier-objs := test_verifier.o libbpf.o
 test_maps-objs := test_maps.o libbpf.o
@@ -28,6 +29,7 @@ tracex4-objs := bpf_load.o libbpf.o tracex4_user.o
 tracex5-objs := bpf_load.o libbpf.o tracex5_user.o
 trace_output-objs := bpf_load.o libbpf.o trace_output_user.o
 lathist-objs := bpf_load.o libbpf.o lathist_user.o
+tcp_trace-objs := bpf_load.o libbpf.o tcp_trace_user.o

 # Tell kbuild to always build the programs
 always := $(hostprogs-y)
@@ -42,6 +44,7 @@ always += tracex5_kern.o
 always += trace_output_kern.o
 always += tcbpf1_kern.o
 always += lathist_kern.o
+always += tcp_trace_kern.o

 HOSTCFLAGS += -I$(objtree)/usr/include

@@ -56,14 +59,16 @@ HOSTLOADLIBES_tracex4 += -lelf -lrt
 HOSTLOADLIBES_tracex5 += -lelf
 HOSTLOADLIBES_trace_output += -lelf -lrt
 HOSTLOADLIBES_lathist += -lelf
+HOSTLOADLIBES_tcp_trace += -lelf

 # point this to your LLVM backend with bpf support
-LLC=$(srctree)/tools/bpf/llvm/bld/Debug+Asserts/bin/llc
+LLC=/home/kafai/local/llvm-git-master/bin/llc
+CLANG=/home/kafai/local/llvm-git-master/bin/clang

 $(obj)/%.o: $(src)/%.c
-   clang $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
+   $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
-D__KERNEL__ -Wno-unused-value -Wno-pointer-sign \
-O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@
-   clang $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
+   $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
-D__KERNEL__ -Wno-unused-value -Wno-pointer-sign \
-O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=asm -o 
$@.s
diff --git a/samples/bpf/bpf_helpers.h b/samples/bpf/bpf_helpers.h
index e84dd3c..df3f00e 100644
--- a/samples/bpf/bpf_helpers.h
+++ b/samples/bpf/bpf_helpers.h
@@ -33,6 +33,10 @@ static int (*bpf_get_current_comm)(void *buf, int buf_size) =
(void *) BPF_FUNC_get_current_comm;
 static int (*bpf_perf_event_output)(void *ctx, void *map, int index, void 
*data, int size) 

Re: [PATCH 0/11] cpufreq: governor: ondemand/conservative data structures rework

2016-02-03 Thread Viresh Kumar
On 04-02-16, 00:12, Rafael J. Wysocki wrote:
> Hi,
> 
> A few days ago I looked at the common code used by the ondemand and 
> conservative
> governors because of the deadlock issue that Viresh has addressed recently
> (http://marc.info/?l=linux-pm=145450832814058=4) and it occurred to me
> that the whole thing was really too tangled and might be made easier to follow
> at least.  I started to work on this and ended up with the following series.
> 
> I'm not really going to stop here, but first, I'd like to let everybody know
> that this is happening and second, I'll need to rebase these patches on the
> ones from Viresh (in the series linked above), but that may take some time
> and I don't want to sit on them for all that long.
> 
> Overall, I'd like the governor code to be cleaner and easier to follow, so we 
> can
> move at least some parts of governor work to utilization update callbacks 
> (invoked
> by the scheduler) or to at least to irq_work so as to reduce the usage of 
> process
> context in cpufreq to absolute minimum.  That's the plan for the future, but 
> for
> now this is just a major cleanup.
> 
> [1/11] Clean up the way in which the default and fallback governors are set 
> up.
> [2/11] Use a common global mutex for dbs_data protection.
> [3/11] Use common global pointer to dbs_data for system-wide governors.

Hi Rafael,

I have some very basic doubts on 2nd and 3rd patch, and so have
stopped reviewing after that because there is too much dependency I
believe on these two.

I will review the rest, if my concerns on the earlier ones are
incorrect.

-- 
viresh


[PATCH RESEND] tcp_estats: ebpf hacks

2016-02-03 Thread Martin KaFai Lau
Signed-off-by: Martin KaFai Lau 
---
 kernel/trace/bpf_trace.c |  20 ++
 samples/Makefile |   2 +-
 samples/bpf/Makefile |  11 +-
 samples/bpf/bpf_helpers.h|   4 +
 samples/bpf/bpf_load.c   |  44 +++--
 samples/bpf/tcp_trace.h  |  51 +
 samples/bpf/tcp_trace_kern.c | 454 +++
 samples/bpf/tcp_trace_user.c | 115 +++
 tools/net/Makefile   |   6 +-
 9 files changed, 689 insertions(+), 18 deletions(-)
 create mode 100644 samples/bpf/tcp_trace.h
 create mode 100644 samples/bpf/tcp_trace_kern.c
 create mode 100644 samples/bpf/tcp_trace_user.c

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 47febbe..977702e 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -68,6 +68,7 @@ static u64 bpf_probe_read(u64 r1, u64 r2, u64 r3, u64 r4, u64 
r5)
void *unsafe_ptr = (void *) (long) r3;
 
return probe_kernel_read(dst, unsafe_ptr, size);
+   /* return __bpf_probe_read_hack(dst, unsafe_ptr, size); */
 }
 
 static const struct bpf_func_proto bpf_probe_read_proto = {
@@ -79,6 +80,25 @@ static const struct bpf_func_proto bpf_probe_read_proto = {
.arg3_type  = ARG_ANYTHING,
 };
 
+static u64 bpf_probe_read_u32(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
+{
+   u32 *dst = (u32 *) (long) r1;
+   int size = (int) r2;
+   u32 *unsafe_ptr = (void *) (long) r3;
+
+   *dst = *unsafe_ptr;
+   return probe_kernel_read(dst, unsafe_ptr, size);
+}
+
+static const struct bpf_func_proto bpf_probe_read_u32_proto = {
+   .func   = bpf_probe_read,
+   .gpl_only   = true,
+   .ret_type   = RET_VOID,
+   .arg1_type  = ARG_PTR_TO_STACK,
+   .arg2_type  = ARG_CONST_STACK_SIZE,
+   .arg3_type  = ARG_ANYTHING,
+};
+
 /*
  * limited trace_printk()
  * only %d %u %x %ld %lu %lx %lld %llu %llx %p %s conversion specifiers allowed
diff --git a/samples/Makefile b/samples/Makefile
index f00257b..fb87be5 100644
--- a/samples/Makefile
+++ b/samples/Makefile
@@ -1,4 +1,4 @@
 # Makefile for Linux samples code
 
 obj-$(CONFIG_SAMPLES)  += kobject/ kprobes/ trace_events/ livepatch/ \
-  hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/
+  hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/ 
bpf/
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 97e5243..02885ae 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -14,6 +14,7 @@ hostprogs-y += tracex4
 hostprogs-y += tracex5
 hostprogs-y += trace_output
 hostprogs-y += lathist
+hostprogs-y += tcp_trace
 
 test_verifier-objs := test_verifier.o libbpf.o
 test_maps-objs := test_maps.o libbpf.o
@@ -28,6 +29,7 @@ tracex4-objs := bpf_load.o libbpf.o tracex4_user.o
 tracex5-objs := bpf_load.o libbpf.o tracex5_user.o
 trace_output-objs := bpf_load.o libbpf.o trace_output_user.o
 lathist-objs := bpf_load.o libbpf.o lathist_user.o
+tcp_trace-objs := bpf_load.o libbpf.o tcp_trace_user.o
 
 # Tell kbuild to always build the programs
 always := $(hostprogs-y)
@@ -42,6 +44,7 @@ always += tracex5_kern.o
 always += trace_output_kern.o
 always += tcbpf1_kern.o
 always += lathist_kern.o
+always += tcp_trace_kern.o
 
 HOSTCFLAGS += -I$(objtree)/usr/include
 
@@ -56,14 +59,16 @@ HOSTLOADLIBES_tracex4 += -lelf -lrt
 HOSTLOADLIBES_tracex5 += -lelf
 HOSTLOADLIBES_trace_output += -lelf -lrt
 HOSTLOADLIBES_lathist += -lelf
+HOSTLOADLIBES_tcp_trace += -lelf
 
 # point this to your LLVM backend with bpf support
-LLC=$(srctree)/tools/bpf/llvm/bld/Debug+Asserts/bin/llc
+LLC=/home/kafai/local/llvm-git-master/bin/llc
+CLANG=/home/kafai/local/llvm-git-master/bin/clang
 
 $(obj)/%.o: $(src)/%.c
-   clang $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
+   $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
-D__KERNEL__ -Wno-unused-value -Wno-pointer-sign \
-O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@
-   clang $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
+   $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
-D__KERNEL__ -Wno-unused-value -Wno-pointer-sign \
-O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=asm -o 
$@.s
diff --git a/samples/bpf/bpf_helpers.h b/samples/bpf/bpf_helpers.h
index e84dd3c..df3f00e 100644
--- a/samples/bpf/bpf_helpers.h
+++ b/samples/bpf/bpf_helpers.h
@@ -33,6 +33,10 @@ static int (*bpf_get_current_comm)(void *buf, int buf_size) =
(void *) BPF_FUNC_get_current_comm;
 static int (*bpf_perf_event_output)(void *ctx, void *map, int index, void 
*data, int size) =
(void *) BPF_FUNC_perf_event_output;
+static unsigned long long (*bpf_get_prandom_u32)(void) =
+   (void *) BPF_FUNC_get_prandom_u32;
+static unsigned long long (*bpf_probe_read_u32)(void *dst, int size, void 
*unsafe_ptr) =
+   (void *) BPF_FUNC_probe_read_u32;
 
 /* llvm builtin functions that eBPF C 

Re: [PATCH v4 09/43] usb: gadget: composite: handle function bind

2016-02-03 Thread kbuild test robot
Hi Robert,

[auto build test WARNING on usb/usb-testing]
[also build test WARNING on v4.5-rc2 next-20160203]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improving the system]

url:
https://github.com/0day-ci/linux/commits/Robert-Baldyga/usb-gadget-composite-introduce-new-function-API/20160203-205850
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git 
usb-testing
reproduce: make htmldocs

All warnings (new ones prefixed by >>):

   include/linux/usb/gadget.h:227: warning: No description found for parameter 
'claimed'
   include/linux/usb/gadget.h:227: warning: No description found for parameter 
'enabled'
   include/linux/usb/gadget.h:652: warning: No description found for parameter 
'quirk_altset_not_supp'
   include/linux/usb/gadget.h:652: warning: No description found for parameter 
'quirk_stall_not_supp'
   include/linux/usb/gadget.h:652: warning: No description found for parameter 
'quirk_zlp_not_supp'
   include/linux/usb/composite.h:114: warning: No description found for 
parameter 'ss_comp'
   include/linux/usb/composite.h:141: warning: No description found for 
parameter 'alt'
   include/linux/usb/composite.h:691: warning: Excess struct/union/enum/typedef 
member 'setup_pending' description in 'usb_composite_dev'
   include/linux/usb/composite.h:691: warning: Excess struct/union/enum/typedef 
member 'os_desc_pending' description in 'usb_composite_dev'
>> drivers/usb/gadget/composite.c:2437: warning: No description found for 
>> parameter 'ep1'
>> drivers/usb/gadget/composite.c:2437: warning: No description found for 
>> parameter 'ep2'
   drivers/usb/gadget/function/f_acm.c:1: warning: no structured comments found
   drivers/usb/gadget/function/f_ecm.c:1: warning: no structured comments found
   drivers/usb/gadget/function/f_subset.c:1: warning: no structured comments 
found
   drivers/usb/gadget/function/f_obex.c:1: warning: no structured comments found
   drivers/usb/gadget/function/f_serial.c:1: warning: no structured comments 
found

vim +/ep1 +2437 drivers/usb/gadget/composite.c

  2421  usb_ep_free_request(cdev->gadget->ep0, cdev->req);
  2422  }
  2423  cdev->next_string_id = 0;
  2424  device_remove_file(>gadget->dev, _attr_suspended);
  2425  }
  2426  
  2427  /**
  2428   * usb_cmp_ep_descs - compare descriptors of two endpoints
  2429   *
  2430   * As currently during autoconfig procedure we take into consideration 
only
  2431   * FullSpeed and SuperSpeed Companion descriptors, we need to compare 
only
  2432   * these descriptors. It they are the same, endpoints are identical from
  2433   * autoconfig point of view.
  2434   */
  2435  static int usb_cmp_ep_descs(struct usb_composite_ep *ep1,
  2436  struct usb_composite_ep *ep2)
> 2437  {
  2438  if (ep1->fs.desc->bLength != ep2->fs.desc->bLength)
  2439  return 0;
  2440  if (usb_endpoint_dir_in(ep1->fs.desc) ^
  2441  usb_endpoint_dir_in(ep2->fs.desc))
  2442  return 0;
  2443  if (ep1->fs.desc->bmAttributes != ep2->fs.desc->bmAttributes)
  2444  return 0;
  2445  if (ep1->fs.desc->wMaxPacketSize != 
ep2->fs.desc->wMaxPacketSize)

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: Binary data


Re: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer

2016-02-03 Thread Viresh Kumar
On 04-02-16, 02:25, Rafael J. Wysocki wrote:
> You are talking about something like this now:
> 
> if (condition)
> goto label;
> 
> return 0;
> 
> label:
> do stuff
> 
> I'm sorry, but I fail to see how this is easier to read than
> 
> if (!condition)
> return 0;
> 
> do stuff

I have seen few people (Like Dan Carpenter), mostly coccinelle guys,
saying that we should write code like this:

if (error)
...

return success;

Though I should accept that I would have written code the way Rafael
has done this time, but those people get back everytime :)

-- 
viresh


Re: [PATCH 3/11] cpufreq: governor: Use common global_dbs_data pointer

2016-02-03 Thread Viresh Kumar
On 04-02-16, 00:22, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki 
> 
> If the ondemand and conservative governors cannot use per-policy
> tunables (CPUFREQ_HAVE_GOVERNOR_PER_POLICY is not set in the cpufreq
> driver), all policy objects point to the same single dbs_data object.
> Additionally, that object is pointed to by a global pointer hidden in
> the governor's data structures.
> 
> There is no reason for that pointer to be buried in those
> data structures, though, so make it explicitly global.
> 
> Signed-off-by: Rafael J. Wysocki 

> Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
> ===
> --- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
> +++ linux-pm/drivers/cpufreq/cpufreq_governor.c
> @@ -22,6 +22,9 @@
>  
>  #include "cpufreq_governor.h"
>  
> +struct dbs_data *global_dbs_data;
> +EXPORT_SYMBOL_GPL(global_dbs_data);

Oh man, please save me from Rafael's Rant :)

I think, this is simply wrong.

Believe me its very difficult for me to say this to you :). You are
way better than me, and I am sure that I haven't understood cupfreq
after so many years :)

Consider a two policy system, who is stopping us from setting ondemand
for one of them and conservative for the other one ? And so, we will
have two gdbs_data ..

Sorry for the noise, if I am being utterly stupid :(

-- 
viresh


Re: N900 sleep mode (in 4.5-rc0, if that matters)

2016-02-03 Thread Tony Lindgren
* Tony Lindgren  [160201 14:12]:
> * Pavel Machek  [160201 13:18]:
> > 
> > No, sorry, that was with 4.4. As you hit "PM regression with commit
> > 5de85b9d57ab PM runtime re-init in v4.5-rc1", I thought I'd avoid
> > v4.5-rc. 
> 
> OK
> 
> > (I assume I have to insmod and rmmod, right? Because powersave is not
> > entered if I simply compile-out usb).
> 
> Depending on what the bootloader does and probably also if
> USB was used during the booting.. So yeah you may need to modprobe
> and then rmmod.
> 
> > Would you have commit ids for those rmmod fixes? It might be good to
> > push them into stable, and I should try again with them applied...
> 
> 05fc459 ("usb: musb: core: Fix handling of the phy notifications")
> 03e43528ab68 ("usb: musb: Fix unbalanced pm_runtime_enable")

Oh and looks like these two phy-twl4030-phy fixes never got
merged from thread "[PATCH 0/2] Two phy-twl4030-usb fixes for
unloading the module":

phy: twl4030-usb: Relase usb phy on unload
phy: twl4030-usb: Fix unbalanced pm_runtime_enable on module reload

I'll resend those. But without those again deeper idle states
are blocked.. And it could be that n900 needs similar additional
patches for it's USB PHY as I've tested things so far only with
phy-twl4030-usb PHY based systems.

Regards,

Tony


Re: [PATCH v10 5/5] Watchdog: ARM SBSA Generic Watchdog half timeout panic support

2016-02-03 Thread Guenter Roeck

On 02/03/2016 03:00 PM, Fu Wei wrote:

On 4 February 2016 at 02:45, Timur Tabi  wrote:

Fu Wei wrote:


As you know I have made the pre-timeout support patch, If people like
it, i am happy to go on upstream it separately.

If we want to use pre-timeout here, user only can use get_pretimeout
and disable panic by setting pretimeout to 0
but user can not really set pretimeout, because "pre-timeout  ==
timeout / 2 (always)".
if user want to change pretimeout, he/she has to set_time instead.



Ok, I think patches 4 and 5 should be combined, and I think the Kconfig
entry should be removed and just use panic_enabled.


Agreed.


NP, will update this patchset like that ,  thanks :-)



Also, if panic is enabled, the timeout needs to be adjusted accordingly
(to only panic after the entire timeout period has expired, not after
half of it). We can not panic the system after timeout / 2.

I am not too happy with the parameter name (panic_enabled). How about
"action", to match machzwd ?

Thanks,
Guenter



Re: [PATCH] staging: wilc1000: Move Macro definition

2016-02-03 Thread Gujulan Elango, Hari Prasath (H.)
On Wed, Feb 03, 2016 at 03:19:50PM -0800, gre...@linuxfoundation.org wrote:
> On Mon, Jan 18, 2016 at 01:42:35PM +, Gujulan Elango, Hari Prasath (H.) 
> wrote:
> > From: Hari Prasath Gujulan Elango 
> > 
> > This patch move's a macro defined in the middle of a structure
> > definition to make it more readable.
> > 
> > Signed-off-by: Hari Prasath Gujulan Elango 
> > ---
> >  drivers/staging/wilc1000/wilc_sdio.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/staging/wilc1000/wilc_sdio.c 
> > b/drivers/staging/wilc1000/wilc_sdio.c
> > index e961b50..875ea68 100644
> > --- a/drivers/staging/wilc1000/wilc_sdio.c
> > +++ b/drivers/staging/wilc1000/wilc_sdio.c
> > @@ -29,12 +29,12 @@ static const struct sdio_device_id wilc_sdio_ids[] = {
> >  };
> >  
> >  #define WILC_SDIO_BLOCK_SIZE 512
> > +#define MAX_NUN_INT_THRPT_ENH2 (5) /* Max num interrupts allowed in 
> > registers 0xf7, 0xf8 */
> >  
> >  typedef struct {
> > bool irq_gpio;
> > u32 block_size;
> > int nint;
> > -#define MAX_NUN_INT_THRPT_ENH2 (5) /* Max num interrupts allowed in 
> > registers 0xf7, 0xf8 */
> 
> No, this is a very common way to show that this define is for this field
> in the structure, please don't change that.
> 
> sorry,
> 
> greg k-h

Thanks Greg,I got the message clear.Please discard this patch.
Regards,
Hari


Re: [PATCHv2] staging: android: ion: use the manged version of DMA memory allocation

2016-02-03 Thread Gujulan Elango, Hari Prasath (H.)
On Wed, Feb 03, 2016 at 10:11:04AM -0800, Laura Abbott wrote:
> On 02/03/2016 04:03 AM, Robin Murphy wrote:
> >On 03/02/16 06:49, Gujulan Elango, Hari Prasath (H.) wrote:
> >>From: Hari Prasath Gujulan Elango 
> >>
> >>Use the managed version of the dma_alloc_coherent() i.e. the
> >>dmam_alloc_coherent() & accordingly cleanup the error handling
> >>part.Also,remove the references to dma_free_coherent
> >
> >That last aspect looks a bit off to me - the heaps don't seem to be 
> >something that exist for the lifetime of the ION "device", given that these 
> >are specific runtime alloc and free calls, rather than the probe and remove 
> >routines. I don't know if CMA heaps are among those which ION creates and 
> >destroys frequently (enough that it apparently kicks off a whole background 
> >thread to manage the freeing), but this looks like a recipe for leaks. If 
> >the free call doesn't actually free the buffer, it's going to remain hanging 
> >around consuming precious CMA area until the ION device itself is torn down, 
> >which is likely never.
> >
> >I wouldn't say it's necessarily inappropriate to use managed DMA resources 
> >here to cover unexpected failure cases for the ION device itself (I see the 
> >comment in ion_device_remove()), but that means still using 
> >dmam_free_coherent() when naturally releasing allocations for other reasons 
> >(i.e. both cases here). Think Java finalisers, rather than C++ destructors.
> >
> >Robin.
> >
> 
> Yes, Robin is correct. These allocations are not tied to the lifetime of the
> device so it is incorrect to move to the manged APIs. The dma_alloc_coherent
> allocations are done on request.
> 
> Ion isn't a good candidate to look at to switch APIs over to the devm
> interface since it does many things in a non-standard way. You should
> probably focus devm efforts outside of Ion (although if you find a
> potential patch I'll certainly review it)
> 
> Thanks,
> Laura
> 
> >>Signed-off-by: Hari Prasath Gujulan Elango 
> >>---
> >>v2:kbuild test robot reported warnings on ununsed
> >>   variables.Those warnings are fixed.
> >>---
> >>  drivers/staging/android/ion/ion_cma_heap.c | 11 ++-
> >>  1 file changed, 2 insertions(+), 9 deletions(-)
> >>
> >>diff --git a/drivers/staging/android/ion/ion_cma_heap.c 
> >>b/drivers/staging/android/ion/ion_cma_heap.c
> >>index a3446da..8cd720b 100644
> >>--- a/drivers/staging/android/ion/ion_cma_heap.c
> >>+++ b/drivers/staging/android/ion/ion_cma_heap.c
> >>@@ -61,7 +61,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct 
> >>ion_buffer *buffer,
> >>  if (!info)
> >>  return ION_CMA_ALLOCATE_FAILED;
> >>
> >>-info->cpu_addr = dma_alloc_coherent(dev, len, &(info->handle),
> >>+info->cpu_addr = dmam_alloc_coherent(dev, len, &(info->handle),
> >>  GFP_HIGHUSER | __GFP_ZERO);
> >>
> >>  if (!info->cpu_addr) {
> >>@@ -71,7 +71,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct 
> >>ion_buffer *buffer,
> >>
> >>  info->table = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
> >>  if (!info->table)
> >>-goto free_mem;
> >>+goto err;
> >>
> >>  if (dma_get_sgtable(dev, info->table, info->cpu_addr, info->handle,
> >>  len))
> >>@@ -83,8 +83,6 @@ static int ion_cma_allocate(struct ion_heap *heap, struct 
> >>ion_buffer *buffer,
> >>
> >>  free_table:
> >>  kfree(info->table);
> >>-free_mem:
> >>-dma_free_coherent(dev, len, info->cpu_addr, info->handle);
> >>  err:
> >>  kfree(info);
> >>  return ION_CMA_ALLOCATE_FAILED;
> >>@@ -92,13 +90,8 @@ err:
> >>
> >>  static void ion_cma_free(struct ion_buffer *buffer)
> >>  {
> >>-struct ion_cma_heap *cma_heap = to_cma_heap(buffer->heap);
> >>-struct device *dev = cma_heap->dev;
> >>  struct ion_cma_buffer_info *info = buffer->priv_virt;
> >>
> >>-dev_dbg(dev, "Release buffer %p\n", buffer);
> >>-/* release memory */
> >>-dma_free_coherent(dev, buffer->size, info->cpu_addr, info->handle);
> >>  /* release sg table */
> >>  sg_free_table(info->table);
> >>  kfree(info->table);
> >>
> >
> 
Robin & Laura,

Thanks for your review comments & I agreee both of you on this. Let's
drop this patch.

Regards
Hari Prasath


Re: [PATCH v4 06/43] usb: gadget: composite: introduce new descriptors format

2016-02-03 Thread kbuild test robot
Hi Robert,

[auto build test WARNING on usb/usb-testing]
[also build test WARNING on v4.5-rc2 next-20160203]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improving the system]

url:
https://github.com/0day-ci/linux/commits/Robert-Baldyga/usb-gadget-composite-introduce-new-function-API/20160203-205850
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git 
usb-testing
reproduce: make htmldocs

All warnings (new ones prefixed by >>):

   include/linux/usb/gadget.h:227: warning: No description found for parameter 
'claimed'
   include/linux/usb/gadget.h:227: warning: No description found for parameter 
'enabled'
   include/linux/usb/gadget.h:652: warning: No description found for parameter 
'quirk_altset_not_supp'
   include/linux/usb/gadget.h:652: warning: No description found for parameter 
'quirk_stall_not_supp'
   include/linux/usb/gadget.h:652: warning: No description found for parameter 
'quirk_zlp_not_supp'
>> include/linux/usb/composite.h:114: warning: No description found for 
>> parameter 'ss_comp'
>> include/linux/usb/composite.h:141: warning: No description found for 
>> parameter 'alt'
   include/linux/usb/composite.h:628: warning: Excess struct/union/enum/typedef 
member 'setup_pending' description in 'usb_composite_dev'
   include/linux/usb/composite.h:628: warning: Excess struct/union/enum/typedef 
member 'os_desc_pending' description in 'usb_composite_dev'
   drivers/usb/gadget/function/f_acm.c:1: warning: no structured comments found
   drivers/usb/gadget/function/f_ecm.c:1: warning: no structured comments found
   drivers/usb/gadget/function/f_subset.c:1: warning: no structured comments 
found
   drivers/usb/gadget/function/f_obex.c:1: warning: no structured comments found
   drivers/usb/gadget/function/f_serial.c:1: warning: no structured comments 
found

vim +/ss_comp +114 include/linux/usb/composite.h

   108  } ss_comp;
   109  
   110  struct list_head vendor_descs;
   111  int vendor_descs_num;
   112  
   113  struct usb_ep *ep;
 > 114  };
   115  
   116  /**
   117   * struct usb_composite_altset - representation of USB altsetting
   118   * @alt.desc: interface (altsetting) descriptor
   119   * @eps: array of endpoints in altsetting
   120   * @eps_num: number of endpoints
   121   * @vendor_descs: list of vendor specific descriptors
   122   * @vendor_descs_num: count of vendor specific descriptors
   123   *
   124   * We have pointer to alt descriptor in union with pointer to descriptor
   125   * header in order to avoid casting in many places in code, because in
   126   * some situations we want to have access to fields of particular type
   127   * of descriptor, while in other situations we want to treat all types
   128   * of descriptors in the same way.
   129   */
   130  struct usb_composite_altset {
   131  union {
   132  struct usb_descriptor_header *header;
   133  struct usb_interface_descriptor *desc;
   134  } alt;
   135  
   136  struct usb_composite_ep **eps;
   137  int eps_num;
   138  
   139  struct list_head vendor_descs;
   140  int vendor_descs_num;
 > 141  };
   142  
   143  /**
   144   * struct usb_composite_intf - representation of USB interface

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: Binary data


Re: [PATCH 2/11] cpufreq: governor: Use common mutex for dbs_data protection

2016-02-03 Thread Viresh Kumar
On 04-02-16, 00:16, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki 
> 
> Every governor relying on the common code in cpufreq_governor.c
> has to provide its own mutex in struct common_dbs_data.  However,
> those mutexes are never used at the same time

Why do you think so? I thought they can always be used in parallel.

Consider 2 or more policies, one can have ondemand as the governor,
whereas other one can have conservative.

If CPUs go online/offline or if governors are switching in parallel,
then cpufreq_governor_dbs() can very much run in parallel for ondemand
and conservative.

Or am I missing something here ?

-- 
viresh


Re: [PATCH] drm/msm/dsi: fix definition of msm_dsi_pll_28nm_8960_init()

2016-02-03 Thread Archit Taneja



On 02/03/2016 07:55 PM, Luis Henriques wrote:

This fixes the following build failure:

drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm.o: In function 
`msm_dsi_pll_28nm_8960_init':
dsi_pll_28nm.c:(.text+0x1198): multiple definition of 
`msm_dsi_pll_28nm_8960_init'
drivers/gpu/drm/msm/dsi/pll/dsi_pll.o:dsi_pll.c:(.text+0x0): first defined here


Thanks for the fix.

Acked-by: Archit Taneja 

Dave,

Could you please queue this for the next -rc cycle since it causes a
build break?

Thanks,
Archit



Signed-off-by: Luis Henriques 
---
  drivers/gpu/drm/msm/dsi/pll/dsi_pll.h | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/pll/dsi_pll.h 
b/drivers/gpu/drm/msm/dsi/pll/dsi_pll.h
index 80b6038334a6..2cf1664723e8 100644
--- a/drivers/gpu/drm/msm/dsi/pll/dsi_pll.h
+++ b/drivers/gpu/drm/msm/dsi/pll/dsi_pll.h
@@ -97,8 +97,8 @@ static inline struct msm_dsi_pll *msm_dsi_pll_28nm_init(
  struct msm_dsi_pll *msm_dsi_pll_28nm_8960_init(struct platform_device *pdev,
   int id);
  #else
-struct msm_dsi_pll *msm_dsi_pll_28nm_8960_init(struct platform_device *pdev,
-  int id)
+static inline struct msm_dsi_pll *msm_dsi_pll_28nm_8960_init(
+   struct platform_device *pdev, int id)
  {
return ERR_PTR(-ENODEV);
  }



--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora 
Forum, hosted by The Linux Foundation


Re: [PATCH 1/11] cpufreq: Clean up default and fallback governor setup

2016-02-03 Thread Viresh Kumar
On 04-02-16, 00:14, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki 
> 
> The preprocessor magic used for setting the default cpufreq governor
> (and for using the performance governor as a fallback one for that
> matter) is really nasty, so replace it with __weak functions and
> overrides.
> 
> Signed-off-by: Rafael J. Wysocki 
> ---
>  drivers/cpufreq/cpufreq.c  |   37 
> ++---
>  drivers/cpufreq/cpufreq_conservative.c |   10 +---
>  drivers/cpufreq/cpufreq_ondemand.c |   34 --
>  drivers/cpufreq/cpufreq_performance.c  |   18 
>  drivers/cpufreq/cpufreq_powersave.c|   10 +---
>  drivers/cpufreq/cpufreq_userspace.c|   10 +---
>  include/linux/cpufreq.h|   25 +-
>  7 files changed, 73 insertions(+), 71 deletions(-)

Acked-by: Viresh Kumar 

-- 
viresh


Re: [Y2038] [PATCH 00/10] Remove CURRENT_TIME and CURRENT_TIME_SEC - PART 1

2016-02-03 Thread Deepa Dinamani
>> These will be the changes to the above function:
>> 1. Function will return the type y2038 safe timespec64 in [2].
>> 2. Function will use y2038 safe 64 bit functions in [2].
>> 3. Function will be extended to perform range checks in [3].
>
> I guess [2] and [3] are really independent of one another
> and can be done in either order, correct?

That is correct.
[2] and [3] are independent of each other .

We might need one more series for bug fixes though.
Or, we can merge these independently.
I will discuss this with you separately.

-Deepa


Re: [Update][PATCH 3/3] cpufreq: governor: Replace timers with utilization update callbacks

2016-02-03 Thread Viresh Kumar
On 03-02-16, 02:16, Rafael J. Wysocki wrote:
> Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
> -void gov_add_timers(struct cpufreq_policy *policy, unsigned int delay)
> +void gov_set_update_util(struct cpu_common_dbs_info *shared,
> +  unsigned int delay_us)
>  {
> + struct cpufreq_policy *policy = shared->policy;
>   struct dbs_data *dbs_data = policy->governor_data;
> - struct cpu_dbs_info *cdbs;
>   int cpu;
>  
> + shared->sample_delay_ns = delay_us * NSEC_PER_USEC;
> + shared->time_stamp = ktime_get();
> +
>   for_each_cpu(cpu, policy->cpus) {
> - cdbs = dbs_data->cdata->get_cpu_cdbs(cpu);
> - cdbs->timer.expires = jiffies + delay;
> - add_timer_on(>timer, cpu);
> + struct cpu_dbs_info *cdbs = dbs_data->cdata->get_cpu_cdbs(cpu);
> +
> + cdbs->last_sample_time = 0;
> + cpufreq_set_update_util_data(cpu, >update_util);

Why no synchronize_rcu() here? This can be called from ondemand
governor on sampling-rate updates ..

>   }
>  }
> -EXPORT_SYMBOL_GPL(gov_add_timers);
> +EXPORT_SYMBOL_GPL(gov_set_update_util);
>  
> -static inline void gov_cancel_timers(struct cpufreq_policy *policy)
> +static inline void gov_clear_update_util(struct cpufreq_policy *policy)
>  {
> - struct dbs_data *dbs_data = policy->governor_data;
> - struct cpu_dbs_info *cdbs;
>   int i;
>  
> - for_each_cpu(i, policy->cpus) {
> - cdbs = dbs_data->cdata->get_cpu_cdbs(i);
> - del_timer_sync(>timer);
> - }
> + for_each_cpu(i, policy->cpus)
> + cpufreq_set_update_util_data(i, NULL);
> +
> + synchronize_rcu();
>  }
>  
>  void gov_cancel_work(struct cpu_common_dbs_info *shared)
>  {
> - /* Tell dbs_timer_handler() to skip queuing up work items. */
> + /* Tell dbs_update_util_handler() to skip queuing up work items. */
>   atomic_inc(>skip_work);
>   /*
> -  * If dbs_timer_handler() is already running, it may not notice the
> -  * incremented skip_work, so wait for it to complete to prevent its work
> -  * item from being queued up after the cancel_work_sync() below.
> -  */
> - gov_cancel_timers(shared->policy);
> - /*
> -  * In case dbs_timer_handler() managed to run and spawn a work item
> -  * before the timers have been canceled, wait for that work item to
> -  * complete and then cancel all of the timers set up by it.  If
> -  * dbs_timer_handler() runs again at that point, it will see the
> -  * positive value of skip_work and won't spawn any more work items.
> +  * If dbs_update_util_handler() is already running, it may not notice
> +  * the incremented skip_work, so wait for it to complete to prevent its
> +  * work item from being queued up after the cancel_work_sync() below.
>*/
> + gov_clear_update_util(shared->policy);
>   cancel_work_sync(>work);

How are we sure that the irq-work can't be pending at this point of
time, which will queue the above works again ?

> - gov_cancel_timers(shared->policy);
>   atomic_set(>skip_work, 0);
>  }
>  EXPORT_SYMBOL_GPL(gov_cancel_work);
>  
> -/* Will return if we need to evaluate cpu load again or not */
> -static bool need_load_eval(struct cpu_common_dbs_info *shared,
> -unsigned int sampling_rate)
> -{
> - if (policy_is_shared(shared->policy)) {
> - ktime_t time_now = ktime_get();
> - s64 delta_us = ktime_us_delta(time_now, shared->time_stamp);
> -
> - /* Do nothing if we recently have sampled */
> - if (delta_us < (s64)(sampling_rate / 2))
> - return false;
> - else
> - shared->time_stamp = time_now;
> - }
> -
> - return true;
> -}
> -
>  static void dbs_work_handler(struct work_struct *work)
>  {
>   struct cpu_common_dbs_info *shared = container_of(work, struct
> @@ -235,14 +212,10 @@ static void dbs_work_handler(struct work
>   struct cpufreq_policy *policy;
>   struct dbs_data *dbs_data;
>   unsigned int sampling_rate, delay;
> - bool eval_load;
>  
>   policy = shared->policy;
>   dbs_data = policy->governor_data;
>  
> - /* Kill all timers */
> - gov_cancel_timers(policy);
> -
>   if (dbs_data->cdata->governor == GOV_CONSERVATIVE) {
>   struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
>  
> @@ -253,37 +226,53 @@ static void dbs_work_handler(struct work
>   sampling_rate = od_tuners->sampling_rate;
>   }
>  
> - eval_load = need_load_eval(shared, sampling_rate);
> -
>   /*
> -  * Make sure cpufreq_governor_limits() isn't evaluating load in
> +  * Make sure cpufreq_governor_limits() isn't evaluating load or the
> +  * ondemand governor isn't reading the time stamp and sampling rate in
>* parallel.
>*/
>   mutex_lock(>timer_mutex);
> - delay = 

linux-api scope (Re: [PATCH v2 11/22] media: dvb-frontend invoke enable/disable_source handlers)

2016-02-03 Thread Andy Lutomirski
[cc list heavily trimmed]

On Wed, Feb 3, 2016 at 8:03 PM, Shuah Khan  wrote:
> Change dvb frontend to check if tuner is free when
> device opened in RW mode. Call to enable_source
> handler either returns with an active pipeline to
> tuner or error if tuner is busy. Tuner is released
> when frontend is released calling the disable_source
> handler.

As an actual subscriber to linux-api, I prefer for the linux-api list
to be lowish-volume and mostly limited to API-related things.  Is this
API related?  Do people think that these series should be sent to
linux-api?

Thanks,
Andy


Re: [PATCH 14/14] ARM: dts: sun8i: Add A83T based Sinovoip Bpi-M3 Board

2016-02-03 Thread Vishnu Patekar
Hello Wens,



On Tue, Feb 2, 2016 at 3:37 PM, Chen-Yu Tsai  wrote:
>
> On Sun, Jan 31, 2016 at 9:21 AM, Vishnu Patekar
>  wrote:
> > This patch adds support for Sinovoip BPI-M3 A83T based board.
> >
> > It has 2G LPDDR3, UART, ethernet, USB, HDMI, USB Sata, MIPI DSI,
> > mic, AP6212 Wifi, etc on it.
> > It is paired with AXP813 PMIC which is almost same as AXP818.
> >
> > Signed-off-by: Vishnu Patekar 
> > ---
> >  arch/arm/boot/dts/Makefile   |  1 +
> >  arch/arm/boot/dts/sun8i-a83t-sinovoip-bpi-m3.dts | 88 
> > 
> >  2 files changed, 89 insertions(+)
> >  create mode 100644 arch/arm/boot/dts/sun8i-a83t-sinovoip-bpi-m3.dts
> >
> > diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile
> > index 58e461a..c0dd016 100644
> > --- a/arch/arm/boot/dts/Makefile
> > +++ b/arch/arm/boot/dts/Makefile
> > @@ -694,6 +694,7 @@ dtb-$(CONFIG_MACH_SUN8I) += \
> > sun8i-a33-sinlinx-sina33.dtb \
> > sun8i-a83t-allwinner-h8homlet-v2.dtb \
> > sun8i-a83t-cubietruck-plus.dtb \
> > +   sun8i-a83t-sinovoip-bpi-m3.dtb \
> > sun8i-h3-orangepi-plus.dtb
> >  dtb-$(CONFIG_MACH_SUN9I) += \
> > sun9i-a80-optimus.dtb \
> > diff --git a/arch/arm/boot/dts/sun8i-a83t-sinovoip-bpi-m3.dts 
> > b/arch/arm/boot/dts/sun8i-a83t-sinovoip-bpi-m3.dts
> > new file mode 100644
> > index 000..fecc7dc
> > --- /dev/null
> > +++ b/arch/arm/boot/dts/sun8i-a83t-sinovoip-bpi-m3.dts
> > @@ -0,0 +1,88 @@
> > +/*
> > + * Copyright 2015 Vishnu Patekar
>
> 2016?
>
> > + * Vishnu Patekar 
> > + *
> > + * This file is dual-licensed: you can use it either under the terms
> > + * of the GPL or the X11 license, at your option. Note that this dual
> > + * licensing only applies to this file, and not this project as a
> > + * whole.
> > + *
> > + *  a) This file is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU General Public License as
> > + * published by the Free Software Foundation; either version 2 of the
> > + * License, or (at your option) any later version.
> > + *
> > + * This file is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > + *
> > + * Or, alternatively,
> > + *
> > + *  b) Permission is hereby granted, free of charge, to any person
> > + * obtaining a copy of this software and associated documentation
> > + * files (the "Software"), to deal in the Software without
> > + * restriction, including without limitation the rights to use,
> > + * copy, modify, merge, publish, distribute, sublicense, and/or
> > + * sell copies of the Software, and to permit persons to whom the
> > + * Software is furnished to do so, subject to the following
> > + * conditions:
> > + *
> > + * The above copyright notice and this permission notice shall be
> > + * included in all copies or substantial portions of the Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> > + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
> > + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> > + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
> > + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
> > + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> > + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> > + * OTHER DEALINGS IN THE SOFTWARE.
> > + */
> > +
> > +/dts-v1/;
> > +#include "sun8i-a83t.dtsi"
> > +#include "sunxi-common-regulators.dtsi"
> > +
> > +/ {
> > +   model = "Sinovoip BananaPi M3 v1.2";
> > +   compatible = "sinovoip,bpi-m3", "allwinner,sun8i-a83t";
> > +
> > +   aliases {
> > +   serial0 = 
> > +   };
> > +
> > +   chosen {
> > +   stdout-path = "serial0:115200n8";
> > +   };
> > +};
> > +
> > + {
> > +   mmc0_cd_pin_bpi_m3: mmc0_cd_pin@0 {
> > +   allwinner,pins = "PF6";
> > +   allwinner,function = "gpio_in";
> > +   allwinner,drive = ;
> > +   allwinner,pull = ;
> > +   };
>
> Maybe we should just put this in the .dtsi and call it
> "mmc0_cd_pin_reference_design"?
>
> We have something similar for sun4i-a10.
Yes, I'll modify it.
>
> > +};
> > +
> > + {
> > +   pinctrl-names = "default";
> > +   pinctrl-0 = <_pins_a>, <_cd_pin_bpi_m3>;
> > +   vmmc-supply = <_vcc3v0>;
> > +   cd-gpios = < 5 6 GPIO_ACTIVE_HIGH>; /* PF6 */
> > +   bus-width = <4>;
> > +   cd-inverted;
> > +   status = "okay";
> > +};
> > +
> > + {
> > +   pinctrl-names = "default";
> > +   pinctrl-0 = <_pins_b>;
> > +   status = "okay";
> > +};
> > +
> > +_rsb {
>
> This goes before uart0.
Okie.
>
> > +  

Re: [RFC] perf: fix building for ARCv1

2016-02-03 Thread Vineet Gupta
+CC Noam

On Wednesday 03 February 2016 09:50 PM, Alexey Brodkin wrote:
>> I agree with the current solution to add -atomic to for arc700 builds.
>> > Although making that default for arc700 tools will be better but that will 
>> > not fix
>> > things before next release of tools etc.
>> > 
>> > But we *do* need to improve generic solution
>> > 1. Add atomics detection in perf to add fall back arch stubs
>> > 2. ARC needs to add syscall for facilitating atomic r-m-w !
> So the most recent ARC GNU tools (2015.12) were just released yesterday
> and still atomics are disabled by default for ARCv1.
> That means perf will continue to fail on building for now.
> 
> Do you think we may apply my initial fix to 4.5 while it is in development and
> then to stable trees as well?

Noam, what's the atomic story for EZChip. Do you support such things for user
space in GNU tools. If -atomic is added to perf user space builds are you guys 
OK!

-Vineet


[PATCH v2 00/22] Sharing media resources across ALSA and au0828 drivers

2016-02-03 Thread Shuah Khan
This patch series updates ALSA driver, and au0828 core
driver to use Managed Media controller API and Media
Controller API to share media resource (tuner).

This Patch v2 series is based on linux_media master.
This work addresses Mauro and Takashi's comments.

Composite or S-Video connector is the input case
is still under discussion and isn't addressed in
this series.

Patches 3 and 4 need documentation updates and will
be sent later this week.

Shuah Khan (22):
  uapi/media.h: Declare interface types for ALSA
  media: Add ALSA Media Controller function entities
  media: Media Controller register/unregister entity_notify API
  media: Media Controller enable/disable source handler API
  media: Media Controller export non locking __media_entity_setup_link()
  media: Media Controller non-locking
__media_entity_pipeline_start/stop()
  media: v4l-core add enable/disable source common interfaces
  media: Move au8522_media_pads enum to au8522.h from au8522_priv.h
  media: au8522 change to create MC pad for ALSA Audio Out
  media: Change v4l-core to check if source is free
  media: dvb-frontend invoke enable/disable_source handlers
  media: au0828 video remove au0828_enable_analog_tuner()
  media: au0828 video change to use v4l_enable_media_source()
  media: au0828 change to use Managed Media Controller API
  media: au0828 handle media_init and media_register window
  media: au0828 create tuner to decoder link in disabled state
  media: au0828 disable tuner to demod link
  media: au0828 Use au8522_media_pads enum for pad defines
  media: au0828-core register entity_notify hook
  media: au0828 add enable, disable source handlers
  sound/usb: Use Media Controller API to share media resources
  media: Ensure media device unregister is done only once

 drivers/media/dvb-core/dvb_frontend.c| 139 ++--
 drivers/media/dvb-core/dvb_frontend.h|   3 +
 drivers/media/dvb-frontends/au8522.h |   8 +
 drivers/media/dvb-frontends/au8522_decoder.c |   1 +
 drivers/media/dvb-frontends/au8522_priv.h|   8 -
 drivers/media/media-device.c |  73 +-
 drivers/media/media-devnode.c|  15 +-
 drivers/media/media-entity.c |  51 -
 drivers/media/usb/au0828/au0828-core.c   | 272 +--
 drivers/media/usb/au0828/au0828-video.c  |  75 +--
 drivers/media/usb/au0828/au0828.h|   4 +
 drivers/media/v4l2-core/Makefile |   2 +-
 drivers/media/v4l2-core/v4l2-fh.c|   2 +
 drivers/media/v4l2-core/v4l2-ioctl.c |  30 +++
 drivers/media/v4l2-core/v4l2-mc.c|  60 +
 drivers/media/v4l2-core/videobuf2-core.c |   4 +
 include/media/media-device.h |  44 
 include/media/media-devnode.h|  17 ++
 include/media/media-entity.h |  12 +
 include/media/v4l2-dev.h |   1 +
 include/media/v4l2-mc.h  |  52 +
 include/uapi/linux/media.h   |  33 +++
 sound/usb/Kconfig|   4 +
 sound/usb/Makefile   |   2 +
 sound/usb/card.c |  14 ++
 sound/usb/card.h |   1 +
 sound/usb/media.c| 319 +++
 sound/usb/media.h|  72 ++
 sound/usb/mixer.h|   1 +
 sound/usb/pcm.c  |  28 ++-
 sound/usb/quirks-table.h |   1 +
 sound/usb/stream.c   |   2 +
 sound/usb/usbaudio.h |   3 +
 33 files changed, 1117 insertions(+), 236 deletions(-)
 create mode 100644 drivers/media/v4l2-core/v4l2-mc.c
 create mode 100644 sound/usb/media.c
 create mode 100644 sound/usb/media.h

-- 
2.5.0



[PATCH v2 01/22] uapi/media.h: Declare interface types for ALSA

2016-02-03 Thread Shuah Khan
Declare the interface types to be used on alsa for
the new G_TOPOLOGY ioctl.

Signed-off-by: Shuah Khan 
---
 drivers/media/media-entity.c | 16 
 include/uapi/linux/media.h   | 22 ++
 2 files changed, 38 insertions(+)

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index f2e4360..6179543 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -65,6 +65,22 @@ static inline const char *intf_type(struct media_interface 
*intf)
return "v4l2-subdev";
case MEDIA_INTF_T_V4L_SWRADIO:
return "swradio";
+   case MEDIA_INTF_T_ALSA_PCM_CAPTURE:
+   return "pcm-capture";
+   case MEDIA_INTF_T_ALSA_PCM_PLAYBACK:
+   return "pcm-playback";
+   case MEDIA_INTF_T_ALSA_CONTROL:
+   return "alsa-control";
+   case MEDIA_INTF_T_ALSA_COMPRESS:
+   return "compress";
+   case MEDIA_INTF_T_ALSA_RAWMIDI:
+   return "rawmidi";
+   case MEDIA_INTF_T_ALSA_HWDEP:
+   return "hwdep";
+   case MEDIA_INTF_T_ALSA_SEQUENCER:
+   return "sequencer";
+   case MEDIA_INTF_T_ALSA_TIMER:
+   return "timer";
default:
return "unknown-intf";
}
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index c9eb42a..ee020e8 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -265,6 +265,7 @@ struct media_links_enum {
 
 #define MEDIA_INTF_T_DVB_BASE  0x0100
 #define MEDIA_INTF_T_V4L_BASE  0x0200
+#define MEDIA_INTF_T_ALSA_BASE 0x0300
 
 /* Interface types */
 
@@ -280,6 +281,27 @@ struct media_links_enum {
 #define MEDIA_INTF_T_V4L_SUBDEV (MEDIA_INTF_T_V4L_BASE + 3)
 #define MEDIA_INTF_T_V4L_SWRADIO (MEDIA_INTF_T_V4L_BASE + 4)
 
+/**
+ * DOC: Media Controller Next Generation ALSA Interface Types
+ *
+ * MEDIA_INTF_T_ALSA_PCM_CAPTURE - PCM Capture Interface (pcm-capture)
+ * MEDIA_INTF_T_ALSA_PCM_PLAYBACK -  PCM Playback Interface (pcm-playback)
+ * MEDIA_INTF_T_ALSA_CONTROL -  ALSA Control Interface (alsa-control)
+ * MEDIA_INTF_T_ALSA_COMPRESS - ALSA Compression Interface (compress)
+ * MEDIA_INTF_T_ALSA_RAWMIDI - ALSA Raw MIDI Interface (rawmidi)
+ * MEDIA_INTF_T_ALSA_HWDEP - ALSA Hardware Dependent Interface (hwdep)
+ * MEDIA_INTF_T_ALSA_SEQUENCER - ALSA Sequencer (sequencer)
+ * MEDIA_INTF_T_ALSA_TIMER - ALSA Timer (timer)
+ */
+#define MEDIA_INTF_T_ALSA_PCM_CAPTURE   (MEDIA_INTF_T_ALSA_BASE)
+#define MEDIA_INTF_T_ALSA_PCM_PLAYBACK  (MEDIA_INTF_T_ALSA_BASE + 1)
+#define MEDIA_INTF_T_ALSA_CONTROL   (MEDIA_INTF_T_ALSA_BASE + 2)
+#define MEDIA_INTF_T_ALSA_COMPRESS  (MEDIA_INTF_T_ALSA_BASE + 3)
+#define MEDIA_INTF_T_ALSA_RAWMIDI   (MEDIA_INTF_T_ALSA_BASE + 4)
+#define MEDIA_INTF_T_ALSA_HWDEP (MEDIA_INTF_T_ALSA_BASE + 5)
+#define MEDIA_INTF_T_ALSA_SEQUENCER (MEDIA_INTF_T_ALSA_BASE + 6)
+#define MEDIA_INTF_T_ALSA_TIMER (MEDIA_INTF_T_ALSA_BASE + 7)
+
 /*
  * MC next gen API definitions
  *
-- 
2.5.0



[PATCH v2 03/22] media: Media Controller register/unregister entity_notify API

2016-02-03 Thread Shuah Khan
Add new interfaces to register and unregister entity_notify
hook to media device. These interfaces allow drivers to add
hooks to take appropriate actions when new entities get added
to a shared media device. For example, au0828 bridge driver
registers an entity_notify hook to create links as needed
between media graph nodes.

Signed-off-by: Shuah Khan 
---
 drivers/media/media-device.c | 61 
 include/media/media-device.h | 25 ++
 2 files changed, 86 insertions(+)

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 4d1c13d..1f5d67e 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -536,6 +536,7 @@ static void media_device_release(struct media_devnode *mdev)
 int __must_check media_device_register_entity(struct media_device *mdev,
  struct media_entity *entity)
 {
+   struct media_entity_notify *notify, *next;
unsigned int i;
int ret;
 
@@ -575,6 +576,11 @@ int __must_check media_device_register_entity(struct 
media_device *mdev,
media_gobj_create(mdev, MEDIA_GRAPH_PAD,
   >pads[i].graph_obj);
 
+   /* invoke entity_notify callbacks */
+   list_for_each_entry_safe(notify, next, >entity_notify, list) {
+   (notify)->notify(entity, notify->notify_data);
+   }
+
spin_unlock(>lock);
 
return 0;
@@ -608,6 +614,8 @@ static void __media_device_unregister_entity(struct 
media_entity *entity)
/* Remove the entity */
media_gobj_destroy(>graph_obj);
 
+   /* invoke entity_notify callbacks to handle entity removal?? */
+
entity->graph_obj.mdev = NULL;
 }
 
@@ -640,6 +648,7 @@ void media_device_init(struct media_device *mdev)
INIT_LIST_HEAD(>interfaces);
INIT_LIST_HEAD(>pads);
INIT_LIST_HEAD(>links);
+   INIT_LIST_HEAD(>entity_notify);
spin_lock_init(>lock);
mutex_init(>graph_mutex);
ida_init(>entity_internal_idx);
@@ -685,11 +694,59 @@ int __must_check __media_device_register(struct 
media_device *mdev,
 }
 EXPORT_SYMBOL_GPL(__media_device_register);
 
+/**
+ * media_device_register_entity_notify - Register a media entity notify
+ * callback with a media device. When a new entity is registered, all
+ * the registered media_entity_notify callbacks are invoked.
+ * @mdev:  The media device
+ * @nptr:  The media_entity_notify
+ */
+int __must_check media_device_register_entity_notify(struct media_device *mdev,
+   struct media_entity_notify *nptr)
+{
+   spin_lock(>lock);
+   list_add_tail(>list, >entity_notify);
+   spin_unlock(>lock);
+   return 0;
+}
+EXPORT_SYMBOL_GPL(media_device_register_entity_notify);
+
+/**
+ * __media_device_unregister_entity_notify - Unregister a media entity notify
+ * callback with a media device. When a new entity is registered, all
+ * the registered media_entity_notify callbacks are invoked.
+ * @mdev:  The media device
+ * @nptr:  The media_entity_notify
+ * Non-locking version. Should be called with mdev->lock held.
+ */
+static void __media_device_unregister_entity_notify(struct media_device *mdev,
+   struct media_entity_notify *nptr)
+{
+   list_del(>list);
+}
+
+/**
+ * media_device_unregister_entity_notify - Unregister a media entity notify
+ * callback with a media device. When a new entity is registered, all
+ * the registered media_entity_notify callbacks are invoked.
+ * @mdev:  The media device
+ * @nptr:  The media_entity_notify
+ */
+void media_device_unregister_entity_notify(struct media_device *mdev,
+   struct media_entity_notify *nptr)
+{
+   spin_lock(>lock);
+   __media_device_unregister_entity_notify(mdev, nptr);
+   spin_unlock(>lock);
+}
+EXPORT_SYMBOL_GPL(media_device_unregister_entity_notify);
+
 void media_device_unregister(struct media_device *mdev)
 {
struct media_entity *entity;
struct media_entity *next;
struct media_interface *intf, *tmp_intf;
+   struct media_entity_notify *notify, *nextp;
 
if (mdev == NULL)
return;
@@ -706,6 +763,10 @@ void media_device_unregister(struct media_device *mdev)
list_for_each_entry_safe(entity, next, >entities, graph_obj.list)
__media_device_unregister_entity(entity);
 
+   /* Remove all entity_notify callbacks from the media device */
+   list_for_each_entry_safe(notify, nextp, >entity_notify, list)
+   __media_device_unregister_entity_notify(mdev, notify);
+
/* Remove all interfaces from the media device */
list_for_each_entry_safe(intf, tmp_intf, >interfaces,
 graph_obj.list) {
diff --git a/include/media/media-device.h b/include/media/media-device.h
index d385589..bad8242a 100644
--- 

[PATCH v2 04/22] media: Media Controller enable/disable source handler API

2016-02-03 Thread Shuah Khan
Add new fields to struct media_device to add enable_source, and
disable_source handlers, and source_priv to stash driver private
data that is used to run these handlers. The enable_source handler
finds source entity for the passed in entity and checks if it is
available. When link is found, it activates it. Disable source
handler deactivates the link.

Bridge driver is expected to implement and set these handlers.

Signed-off-by: Shuah Khan 
---
 include/media/media-device.h | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/include/media/media-device.h b/include/media/media-device.h
index bad8242a..9415f1b 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -333,6 +333,25 @@ struct media_device {
/* Serializes graph operations. */
struct mutex graph_mutex;
 
+   /* Handlers to find source entity for the sink entity and
+* check if it is available, and activate the link using
+* media_entity_setup_link() interface and start pipeline
+* from the source to the entity.
+* Bridge driver is expected to implement and set the
+* handler when media_device is registered or when
+* bridge driver finds the media_device during probe.
+* Bridge driver sets source_priv with information
+* necessary to run enable/disable source handlers.
+*
+* Use-case: find tuner entity connected to the decoder
+* entity and check if it is available, and activate the
+* using media_entity_setup_link() if it is available.
+   */
+   void *source_priv;
+   int (*enable_source)(struct media_entity *entity,
+struct media_pipeline *pipe);
+   void (*disable_source)(struct media_entity *entity);
+
int (*link_notify)(struct media_link *link, u32 flags,
   unsigned int notification);
 };
-- 
2.5.0



[PATCH v2 08/22] media: Move au8522_media_pads enum to au8522.h from au8522_priv.h

2016-02-03 Thread Shuah Khan
Move the au8522_media_pads enum to au8522.h
from au8522_priv.h to export them. This will
allow au0828-core to use these defines instead
of hard-coding them them.

Signed-off-by: Shuah Khan 
---
 drivers/media/dvb-frontends/au8522.h  | 7 +++
 drivers/media/dvb-frontends/au8522_priv.h | 8 
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/media/dvb-frontends/au8522.h 
b/drivers/media/dvb-frontends/au8522.h
index dde6158..3c72f40 100644
--- a/drivers/media/dvb-frontends/au8522.h
+++ b/drivers/media/dvb-frontends/au8522.h
@@ -90,4 +90,11 @@ enum au8522_audio_input {
AU8522_AUDIO_SIF,
 };
 
+enum au8522_media_pads {
+   AU8522_PAD_INPUT,
+   AU8522_PAD_VID_OUT,
+   AU8522_PAD_VBI_OUT,
+
+   AU8522_NUM_PADS
+};
 #endif /* __AU8522_H__ */
diff --git a/drivers/media/dvb-frontends/au8522_priv.h 
b/drivers/media/dvb-frontends/au8522_priv.h
index 404a0cb..505215a 100644
--- a/drivers/media/dvb-frontends/au8522_priv.h
+++ b/drivers/media/dvb-frontends/au8522_priv.h
@@ -39,14 +39,6 @@
 #define AU8522_DIGITAL_MODE 1
 #define AU8522_SUSPEND_MODE 2
 
-enum au8522_media_pads {
-   AU8522_PAD_INPUT,
-   AU8522_PAD_VID_OUT,
-   AU8522_PAD_VBI_OUT,
-
-   AU8522_NUM_PADS
-};
-
 struct au8522_state {
struct i2c_client *c;
struct i2c_adapter *i2c;
-- 
2.5.0



[PATCH v2 09/22] media: au8522 change to create MC pad for ALSA Audio Out

2016-02-03 Thread Shuah Khan
Add new pad for ALSA Audio Out to au8522_media_pads.

Signed-off-by: Shuah Khan 
---
 drivers/media/dvb-frontends/au8522.h | 1 +
 drivers/media/dvb-frontends/au8522_decoder.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/media/dvb-frontends/au8522.h 
b/drivers/media/dvb-frontends/au8522.h
index 3c72f40..d7a997f 100644
--- a/drivers/media/dvb-frontends/au8522.h
+++ b/drivers/media/dvb-frontends/au8522.h
@@ -94,6 +94,7 @@ enum au8522_media_pads {
AU8522_PAD_INPUT,
AU8522_PAD_VID_OUT,
AU8522_PAD_VBI_OUT,
+   AU8522_PAD_AUDIO_OUT,
 
AU8522_NUM_PADS
 };
diff --git a/drivers/media/dvb-frontends/au8522_decoder.c 
b/drivers/media/dvb-frontends/au8522_decoder.c
index 73612c5..0ab9f1e 100644
--- a/drivers/media/dvb-frontends/au8522_decoder.c
+++ b/drivers/media/dvb-frontends/au8522_decoder.c
@@ -766,6 +766,7 @@ static int au8522_probe(struct i2c_client *client,
state->pads[AU8522_PAD_INPUT].flags = MEDIA_PAD_FL_SINK;
state->pads[AU8522_PAD_VID_OUT].flags = MEDIA_PAD_FL_SOURCE;
state->pads[AU8522_PAD_VBI_OUT].flags = MEDIA_PAD_FL_SOURCE;
+   state->pads[AU8522_PAD_AUDIO_OUT].flags = MEDIA_PAD_FL_SOURCE;
sd->entity.function = MEDIA_ENT_F_ATV_DECODER;
 
ret = media_entity_pads_init(>entity, ARRAY_SIZE(state->pads),
-- 
2.5.0



[PATCH v2 07/22] media: v4l-core add enable/disable source common interfaces

2016-02-03 Thread Shuah Khan
Add a new interfaces to be used by v4l-core to invoke enable
source and disable_source handlers in the media_device. The
enable_source helper function invokes the enable_source handler
to find media source entity connected to the entity and check
is it is available or busy. If source is available, link is
activated and pipeline is started. The disable_source helper
function invokes the disable_source handler to deactivate and
stop the pipeline.

Signed-off-by: Shuah Khan 
---
 drivers/media/v4l2-core/Makefile  |  2 +-
 drivers/media/v4l2-core/v4l2-mc.c | 60 +++
 include/media/v4l2-dev.h  |  1 +
 include/media/v4l2-mc.h   | 52 +
 4 files changed, 114 insertions(+), 1 deletion(-)
 create mode 100644 drivers/media/v4l2-core/v4l2-mc.c

diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Makefile
index 1dc8bba..c6acc01 100644
--- a/drivers/media/v4l2-core/Makefile
+++ b/drivers/media/v4l2-core/Makefile
@@ -6,7 +6,7 @@ tuner-objs  :=  tuner-core.o
 
 videodev-objs  :=  v4l2-dev.o v4l2-ioctl.o v4l2-device.o v4l2-fh.o \
v4l2-event.o v4l2-ctrls.o v4l2-subdev.o v4l2-clk.o \
-   v4l2-async.o
+   v4l2-async.o v4l2-mc.o
 ifeq ($(CONFIG_COMPAT),y)
   videodev-objs += v4l2-compat-ioctl32.o
 endif
diff --git a/drivers/media/v4l2-core/v4l2-mc.c 
b/drivers/media/v4l2-core/v4l2-mc.c
new file mode 100644
index 000..87416df
--- /dev/null
+++ b/drivers/media/v4l2-core/v4l2-mc.c
@@ -0,0 +1,60 @@
+/*
+ * v4l2-mc.c - Media Controller V4L2 Common Interfaces
+ *
+ * Copyright (C) 2016 Shuah Khan 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+int v4l_enable_media_source(struct video_device *vdev)
+{
+#ifdef CONFIG_MEDIA_CONTROLLER
+   struct media_device *mdev = vdev->entity.graph_obj.mdev;
+   int ret;
+
+   if (!mdev || !mdev->enable_source)
+   return 0;
+   ret = mdev->enable_source(>entity, >pipe);
+   if (ret)
+   return -EBUSY;
+   return 0;
+#endif /* CONFIG_MEDIA_CONTROLLER */
+   return 0;
+}
+EXPORT_SYMBOL_GPL(v4l_enable_media_source);
+
+void v4l_disable_media_source(struct video_device *vdev)
+{
+#ifdef CONFIG_MEDIA_CONTROLLER
+   struct media_device *mdev = vdev->entity.graph_obj.mdev;
+
+   if (mdev && mdev->disable_source)
+   mdev->disable_source(>entity);
+#endif /* CONFIG_MEDIA_CONTROLLER */
+}
+EXPORT_SYMBOL_GPL(v4l_disable_media_source);
+
+int v4l_vb2q_enable_media_source(struct vb2_queue *q)
+{
+#ifdef CONFIG_MEDIA_CONTROLLER
+   struct v4l2_fh *fh = q->owner;
+
+   return v4l_enable_media_source(fh->vdev);
+#endif /* CONFIG_MEDIA_CONTROLLER */
+   return 0;
+}
+EXPORT_SYMBOL_GPL(v4l_vb2q_enable_media_source);
+
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index eeabf20..76056ab 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -87,6 +87,7 @@ struct video_device
 #if defined(CONFIG_MEDIA_CONTROLLER)
struct media_entity entity;
struct media_intf_devnode *intf_devnode;
+   struct media_pipeline pipe;
 #endif
/* device ops */
const struct v4l2_file_operations *fops;
diff --git a/include/media/v4l2-mc.h b/include/media/v4l2-mc.h
index df11519..df1a98f 100644
--- a/include/media/v4l2-mc.h
+++ b/include/media/v4l2-mc.h
@@ -14,6 +14,11 @@
  * GNU General Public License for more details.
  */
 
+#ifndef _V4L2_MC_H
+#define _V4L2_MC_H
+
+#include 
+
 /**
  * enum tuner_pad_index - tuner pad index for MEDIA_ENT_F_TUNER
  *
@@ -89,3 +94,50 @@ enum demod_pad_index {
DEMOD_PAD_VBI_OUT,
DEMOD_NUM_PADS
 };
+
+/**
+ * v4l_enable_media_source() - Hold media source for exclusive use
+ * if free
+ *
+ * @vdev - poniter to struct video_device
+ *
+ * This interface calls enable_source handler to determine if
+ * media source is free for use. The enable_source handler is
+ * responsible for checking is the media source is free and
+ * start a pipeline between the media source and the media
+ * entity associated with the video device. This interface
+ * should be called from v4l2-core and dvb-core interfaces
+ * that change the source configuration.
+ *
+ * Return: returns zero on success or a negative error code.
+ */
+int v4l_enable_media_source(struct video_device *vdev);
+
+/**
+ * v4l_disable_media_source() -Release media 

[PATCH v2 10/22] media: Change v4l-core to check if source is free

2016-02-03 Thread Shuah Khan
Change s_input, s_fmt, s_tuner, s_frequency, querystd,
s_hw_freq_seek, and vb2_core_streamon interfaces that
alter the tuner configuration to check if it is free,
by calling v4l_enable_media_source(). If source isn't
free, return -EBUSY. v4l_disable_media_source() is
called from v4l2_fh_exit() to release tuner (source).
vb2_core_streamon() uses v4l_vb2q_enable_media_source().

Signed-off-by: Shuah Khan 
---
 drivers/media/v4l2-core/v4l2-fh.c|  2 ++
 drivers/media/v4l2-core/v4l2-ioctl.c | 30 ++
 drivers/media/v4l2-core/videobuf2-core.c |  4 
 3 files changed, 36 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-fh.c 
b/drivers/media/v4l2-core/v4l2-fh.c
index c97067a..c183f09 100644
--- a/drivers/media/v4l2-core/v4l2-fh.c
+++ b/drivers/media/v4l2-core/v4l2-fh.c
@@ -29,6 +29,7 @@
 #include 
 #include 
 #include 
+#include 
 
 void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev)
 {
@@ -92,6 +93,7 @@ void v4l2_fh_exit(struct v4l2_fh *fh)
 {
if (fh->vdev == NULL)
return;
+   v4l_disable_media_source(fh->vdev);
v4l2_event_unsubscribe_all(fh);
fh->vdev = NULL;
 }
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index 8a018c6..ceaa44a 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -1041,6 +1042,12 @@ static int v4l_querycap(const struct v4l2_ioctl_ops *ops,
 static int v4l_s_input(const struct v4l2_ioctl_ops *ops,
struct file *file, void *fh, void *arg)
 {
+   struct video_device *vfd = video_devdata(file);
+   int ret;
+
+   ret = v4l_enable_media_source(vfd);
+   if (ret)
+   return ret;
return ops->vidioc_s_input(file, fh, *(unsigned int *)arg);
 }
 
@@ -1448,6 +1455,9 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops,
bool is_tx = vfd->vfl_dir != VFL_DIR_RX;
int ret;
 
+   ret = v4l_enable_media_source(vfd);
+   if (ret)
+   return ret;
v4l_sanitize_format(p);
 
switch (p->type) {
@@ -1637,7 +1647,11 @@ static int v4l_s_tuner(const struct v4l2_ioctl_ops *ops,
 {
struct video_device *vfd = video_devdata(file);
struct v4l2_tuner *p = arg;
+   int ret;
 
+   ret = v4l_enable_media_source(vfd);
+   if (ret)
+   return ret;
p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
return ops->vidioc_s_tuner(file, fh, p);
@@ -1691,7 +1705,11 @@ static int v4l_s_frequency(const struct v4l2_ioctl_ops 
*ops,
struct video_device *vfd = video_devdata(file);
const struct v4l2_frequency *p = arg;
enum v4l2_tuner_type type;
+   int ret;
 
+   ret = v4l_enable_media_source(vfd);
+   if (ret)
+   return ret;
if (vfd->vfl_type == VFL_TYPE_SDR) {
if (p->type != V4L2_TUNER_SDR && p->type != V4L2_TUNER_RF)
return -EINVAL;
@@ -1746,7 +1764,11 @@ static int v4l_s_std(const struct v4l2_ioctl_ops *ops,
 {
struct video_device *vfd = video_devdata(file);
v4l2_std_id id = *(v4l2_std_id *)arg, norm;
+   int ret;
 
+   ret = v4l_enable_media_source(vfd);
+   if (ret)
+   return ret;
norm = id & vfd->tvnorms;
if (vfd->tvnorms && !norm)  /* Check if std is supported */
return -EINVAL;
@@ -1760,7 +1782,11 @@ static int v4l_querystd(const struct v4l2_ioctl_ops *ops,
 {
struct video_device *vfd = video_devdata(file);
v4l2_std_id *p = arg;
+   int ret;
 
+   ret = v4l_enable_media_source(vfd);
+   if (ret)
+   return ret;
/*
 * If no signal is detected, then the driver should return
 * V4L2_STD_UNKNOWN. Otherwise it should return tvnorms with
@@ -1779,7 +1805,11 @@ static int v4l_s_hw_freq_seek(const struct 
v4l2_ioctl_ops *ops,
struct video_device *vfd = video_devdata(file);
struct v4l2_hw_freq_seek *p = arg;
enum v4l2_tuner_type type;
+   int ret;
 
+   ret = v4l_enable_media_source(vfd);
+   if (ret)
+   return ret;
/* s_hw_freq_seek is not supported for SDR for now */
if (vfd->vfl_type == VFL_TYPE_SDR)
return -EINVAL;
diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index ec5b78e..d381478 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -25,6 +25,7 @@
 #include 
 
 #include 
+#include 
 
 #include 
 
@@ -1873,6 +1874,9 @@ int vb2_core_streamon(struct vb2_queue *q, unsigned int 
type)
 * are available.
 */
if (q->queued_count >= q->min_buffers_needed) {
+   ret = 

[PATCH v2 06/22] media: Media Controller non-locking __media_entity_pipeline_start/stop()

2016-02-03 Thread Shuah Khan
Add non-locking __media_entity_pipeline_start/stop() interfaces
to be called from code paths that hold the graph_mutex. For this
change, the media_entity_pipeline_start() routine is renamed to
__media_entity_pipeline_start() minus the graph_mutex lock and
unlock. media_entity_pipeline_start() now calls the non-locking
__media_entity_pipeline_start() holding the graph_lock. The stop
interface, media_entity_pipeline_stop() routine is renamed to
__media_entity_pipeline_stop() minus the graph_mutex lock and
unlock. media_entity_pipeline_stop() now calls the non-locking
__media_entity_pipeline_stop() holding the graph_lock.

Signed-off-by: Shuah Khan 
---
 drivers/media/media-entity.c | 34 --
 include/media/media-entity.h | 12 
 2 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 9b4d712..b78e4c2 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -365,8 +365,8 @@ EXPORT_SYMBOL_GPL(media_entity_graph_walk_next);
  * Pipeline management
  */
 
-__must_check int media_entity_pipeline_start(struct media_entity *entity,
-struct media_pipeline *pipe)
+__must_check int __media_entity_pipeline_start(struct media_entity *entity,
+  struct media_pipeline *pipe)
 {
struct media_device *mdev = entity->graph_obj.mdev;
struct media_entity_graph *graph = >graph;
@@ -374,8 +374,6 @@ __must_check int media_entity_pipeline_start(struct 
media_entity *entity,
struct media_link *link;
int ret;
 
-   mutex_lock(>graph_mutex);
-
if (!pipe->streaming_count++) {
ret = media_entity_graph_walk_init(>graph, mdev);
if (ret)
@@ -456,8 +454,6 @@ __must_check int media_entity_pipeline_start(struct 
media_entity *entity,
}
}
 
-   mutex_unlock(>graph_mutex);
-
return 0;
 
 error:
@@ -487,19 +483,28 @@ error_graph_walk_start:
if (!--pipe->streaming_count)
media_entity_graph_walk_cleanup(graph);
 
-   mutex_unlock(>graph_mutex);
+   return ret;
+}
+EXPORT_SYMBOL_GPL(__media_entity_pipeline_start);
 
+__must_check int media_entity_pipeline_start(struct media_entity *entity,
+struct media_pipeline *pipe)
+{
+   struct media_device *mdev = entity->graph_obj.mdev;
+   int ret;
+
+   mutex_lock(>graph_mutex);
+   ret = __media_entity_pipeline_start(entity, pipe);
+   mutex_unlock(>graph_mutex);
return ret;
 }
 EXPORT_SYMBOL_GPL(media_entity_pipeline_start);
 
-void media_entity_pipeline_stop(struct media_entity *entity)
+void __media_entity_pipeline_stop(struct media_entity *entity)
 {
-   struct media_device *mdev = entity->graph_obj.mdev;
struct media_entity_graph *graph = >pipe->graph;
struct media_pipeline *pipe = entity->pipe;
 
-   mutex_lock(>graph_mutex);
 
WARN_ON(!pipe->streaming_count);
media_entity_graph_walk_start(graph, entity);
@@ -516,6 +521,15 @@ void media_entity_pipeline_stop(struct media_entity 
*entity)
if (!--pipe->streaming_count)
media_entity_graph_walk_cleanup(graph);
 
+}
+EXPORT_SYMBOL_GPL(__media_entity_pipeline_stop);
+
+void media_entity_pipeline_stop(struct media_entity *entity)
+{
+   struct media_device *mdev = entity->graph_obj.mdev;
+
+   mutex_lock(>graph_mutex);
+   __media_entity_pipeline_stop(entity);
mutex_unlock(>graph_mutex);
 }
 EXPORT_SYMBOL_GPL(media_entity_pipeline_stop);
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index fe485d3..c7583db 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -832,6 +832,12 @@ media_entity_graph_walk_next(struct media_entity_graph 
*graph);
  */
 __must_check int media_entity_pipeline_start(struct media_entity *entity,
 struct media_pipeline *pipe);
+/**
+ * non-locking __media_entity_pipeline_start() can be called from
+ * code paths that hold the graph_mutex
+ */
+__must_check int __media_entity_pipeline_start(struct media_entity *entity,
+  struct media_pipeline *pipe);
 
 /**
  * media_entity_pipeline_stop - Mark a pipeline as not streaming
@@ -848,6 +854,12 @@ __must_check int media_entity_pipeline_start(struct 
media_entity *entity,
 void media_entity_pipeline_stop(struct media_entity *entity);
 
 /**
+ * non-locking __media_entity_pipeline_stop() can be called from
+ * code paths that hold the graph_mutex
+ */
+void __media_entity_pipeline_stop(struct media_entity *entity);
+
+/**
  * media_devnode_create() - creates and initializes a device node interface
  *
  * @mdev:  pointer to struct _device
-- 
2.5.0



[PATCH v2 12/22] media: au0828 video remove au0828_enable_analog_tuner()

2016-02-03 Thread Shuah Khan
Remove au0828_enable_analog_tuner() as it is
no longer needed because v4l2-core implements
common interfaces to check for media source
availability.

In addition, queue_setup() no longer needs the
tuner availability check since v4l2-core does it.

Signed-off-by: Shuah Khan 
---
 drivers/media/usb/au0828/au0828-video.c | 61 -
 1 file changed, 61 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-video.c 
b/drivers/media/usb/au0828/au0828-video.c
index 8c54fd2..81952c8 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -638,64 +638,6 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, 
struct urb *urb)
return rc;
 }
 
-static int au0828_enable_analog_tuner(struct au0828_dev *dev)
-{
-#ifdef CONFIG_MEDIA_CONTROLLER
-   struct media_device *mdev = dev->media_dev;
-   struct media_entity *source;
-   struct media_link *link, *found_link = NULL;
-   int ret, active_links = 0;
-
-   if (!mdev || !dev->decoder)
-   return 0;
-
-   /*
-* This will find the tuner that is connected into the decoder.
-* Technically, this is not 100% correct, as the device may be
-* using an analog input instead of the tuner. However, as we can't
-* do DVB streaming while the DMA engine is being used for V4L2,
-* this should be enough for the actual needs.
-*/
-   list_for_each_entry(link, >decoder->links, list) {
-   if (link->sink->entity == dev->decoder) {
-   found_link = link;
-   if (link->flags & MEDIA_LNK_FL_ENABLED)
-   active_links++;
-   break;
-   }
-   }
-
-   if (active_links == 1 || !found_link)
-   return 0;
-
-   source = found_link->source->entity;
-   list_for_each_entry(link, >links, list) {
-   struct media_entity *sink;
-   int flags = 0;
-
-   sink = link->sink->entity;
-
-   if (sink == dev->decoder)
-   flags = MEDIA_LNK_FL_ENABLED;
-
-   ret = media_entity_setup_link(link, flags);
-   if (ret) {
-   pr_err(
-   "Couldn't change link %s->%s to %s. Error %d\n",
-   source->name, sink->name,
-   flags ? "enabled" : "disabled",
-   ret);
-   return ret;
-   } else
-   au0828_isocdbg(
-   "link %s->%s was %s\n",
-   source->name, sink->name,
-   flags ? "ENABLED" : "disabled");
-   }
-#endif
-   return 0;
-}
-
 static int queue_setup(struct vb2_queue *vq,
   unsigned int *nbuffers, unsigned int *nplanes,
   unsigned int sizes[], void *alloc_ctxs[])
@@ -707,9 +649,6 @@ static int queue_setup(struct vb2_queue *vq,
return sizes[0] < size ? -EINVAL : 0;
*nplanes = 1;
sizes[0] = size;
-
-   au0828_enable_analog_tuner(dev);
-
return 0;
 }
 
-- 
2.5.0



[PATCH v2 11/22] media: dvb-frontend invoke enable/disable_source handlers

2016-02-03 Thread Shuah Khan
Change dvb frontend to check if tuner is free when
device opened in RW mode. Call to enable_source
handler either returns with an active pipeline to
tuner or error if tuner is busy. Tuner is released
when frontend is released calling the disable_source
handler.

Signed-off-by: Shuah Khan 
---
 drivers/media/dvb-core/dvb_frontend.c | 139 +-
 drivers/media/dvb-core/dvb_frontend.h |   3 +
 2 files changed, 24 insertions(+), 118 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_frontend.c 
b/drivers/media/dvb-core/dvb_frontend.c
index 03cc508..2b17e8b 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -131,11 +131,6 @@ struct dvb_frontend_private {
int quality;
unsigned int check_wrapped;
enum dvbfe_search algo_status;
-
-#if defined(CONFIG_MEDIA_CONTROLLER_DVB)
-   struct media_pipeline pipe;
-   struct media_entity *pipe_start_entity;
-#endif
 };
 
 static void dvb_frontend_wakeup(struct dvb_frontend *fe);
@@ -596,104 +591,12 @@ static void dvb_frontend_wakeup(struct dvb_frontend *fe)
wake_up_interruptible(>wait_queue);
 }
 
-/**
- * dvb_enable_media_tuner() - tries to enable the DVB tuner
- *
- * @fe:struct dvb_frontend pointer
- *
- * This function ensures that just one media tuner is enabled for a given
- * frontend. It has two different behaviors:
- * - For trivial devices with just one tuner:
- *   it just enables the existing tuner->fe link
- * - For devices with more than one tuner:
- *   It is up to the driver to implement the logic that will enable one tuner
- *   and disable the other ones. However, if more than one tuner is enabled for
- *   the same frontend, it will print an error message and return -EINVAL.
- *
- * At return, it will return the error code returned by 
media_entity_setup_link,
- * or 0 if everything is OK, if no tuner is linked to the frontend or if the
- * mdev is NULL.
- */
-#ifdef CONFIG_MEDIA_CONTROLLER_DVB
-static int dvb_enable_media_tuner(struct dvb_frontend *fe)
-{
-   struct dvb_frontend_private *fepriv = fe->frontend_priv;
-   struct dvb_adapter *adapter = fe->dvb;
-   struct media_device *mdev = adapter->mdev;
-   struct media_entity  *entity, *source;
-   struct media_link *link, *found_link = NULL;
-   int ret, n_links = 0, active_links = 0;
-
-   fepriv->pipe_start_entity = NULL;
-
-   if (!mdev)
-   return 0;
-
-   entity = fepriv->dvbdev->entity;
-   fepriv->pipe_start_entity = entity;
-
-   list_for_each_entry(link, >links, list) {
-   if (link->sink->entity == entity) {
-   found_link = link;
-   n_links++;
-   if (link->flags & MEDIA_LNK_FL_ENABLED)
-   active_links++;
-   }
-   }
-
-   if (!n_links || active_links == 1 || !found_link)
-   return 0;
-
-   /*
-* If a frontend has more than one tuner linked, it is up to the driver
-* to select with one will be the active one, as the frontend core can't
-* guess. If the driver doesn't do that, it is a bug.
-*/
-   if (n_links > 1 && active_links != 1) {
-   dev_err(fe->dvb->device,
-   "WARNING: there are %d active links among %d tuners. 
This is a driver's bug!\n",
-   active_links, n_links);
-   return -EINVAL;
-   }
-
-   source = found_link->source->entity;
-   fepriv->pipe_start_entity = source;
-   list_for_each_entry(link, >links, list) {
-   struct media_entity *sink;
-   int flags = 0;
-
-   sink = link->sink->entity;
-   if (sink == entity)
-   flags = MEDIA_LNK_FL_ENABLED;
-
-   ret = media_entity_setup_link(link, flags);
-   if (ret) {
-   dev_err(fe->dvb->device,
-   "Couldn't change link %s->%s to %s. Error %d\n",
-   source->name, sink->name,
-   flags ? "enabled" : "disabled",
-   ret);
-   return ret;
-   } else
-   dev_dbg(fe->dvb->device,
-   "link %s->%s was %s\n",
-   source->name, sink->name,
-   flags ? "ENABLED" : "disabled");
-   }
-   return 0;
-}
-#endif
-
 static int dvb_frontend_thread(void *data)
 {
struct dvb_frontend *fe = data;
struct dvb_frontend_private *fepriv = fe->frontend_priv;
enum fe_status s;
enum dvbfe_algo algo;
-#ifdef CONFIG_MEDIA_CONTROLLER_DVB
-   int ret;
-#endif
-
bool re_tune = false;
bool semheld = false;
 
@@ -706,20 +609,6 @@ static int dvb_frontend_thread(void *data)
fepriv->wakeup = 0;

[PATCH v2 13/22] media: au0828 video change to use v4l_enable_media_source()

2016-02-03 Thread Shuah Khan
Change au0828 to check if tuner is free or not
before changing tuner configuration.

vidioc_g_tuner(), and au0828_v4l2_close() now call
v4l-core interface v4l_enable_media_source() before
changing tuner configuration.

Signed-off-by: Shuah Khan 
---
 drivers/media/usb/au0828/au0828-video.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-video.c 
b/drivers/media/usb/au0828/au0828-video.c
index 81952c8..8087215 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -1006,8 +1006,12 @@ static int au0828_v4l2_close(struct file *filp)
goto end;
 
if (dev->users == 1) {
-   /* Save some power by putting tuner to sleep */
-   v4l2_device_call_all(>v4l2_dev, 0, core, s_power, 0);
+   /* Save some power by putting tuner to sleep, if it is free */
+   /* What happens when radio is using tuner?? */
+   ret = v4l_enable_media_source(vdev);
+   if (ret == 0)
+   v4l2_device_call_all(>v4l2_dev, 0, core,
+s_power, 0);
dev->std_set_in_tuner_core = 0;
 
/* When close the device, set the usb intf0 into alt0 to free
@@ -1408,10 +1412,16 @@ static int vidioc_s_audio(struct file *file, void 
*priv, const struct v4l2_audio
 static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
 {
struct au0828_dev *dev = video_drvdata(file);
+   struct video_device *vfd = video_devdata(file);
+   int ret;
 
if (t->index != 0)
return -EINVAL;
 
+   ret = v4l_enable_media_source(vfd);
+   if (ret)
+   return ret;
+
dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
dev->std_set_in_tuner_core, dev->dev_state);
 
-- 
2.5.0



[PATCH v2 17/22] media: au0828 disable tuner to demod link

2016-02-03 Thread Shuah Khan
Change au0828_create_media_graph() to find and disable
tuner and demod link. This helps avoid an additional
disable step when tuner is requested by video or audio.

Signed-off-by: Shuah Khan 
---
 drivers/media/usb/au0828/au0828-core.c | 20 +++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/au0828/au0828-core.c 
b/drivers/media/usb/au0828/au0828-core.c
index 868babe..b02a122 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -254,7 +254,7 @@ static int au0828_create_media_graph(struct au0828_dev *dev)
 #ifdef CONFIG_MEDIA_CONTROLLER
struct media_device *mdev = dev->media_dev;
struct media_entity *entity;
-   struct media_entity *tuner = NULL, *decoder = NULL;
+   struct media_entity *tuner = NULL, *decoder = NULL, *demod = NULL;
int i, ret;
 
if (!mdev)
@@ -268,6 +268,9 @@ static int au0828_create_media_graph(struct au0828_dev *dev)
case MEDIA_ENT_F_ATV_DECODER:
decoder = entity;
break;
+   case MEDIA_ENT_F_DTV_DEMOD:
+   demod = entity;
+   break;
}
}
 
@@ -322,6 +325,21 @@ static int au0828_create_media_graph(struct au0828_dev 
*dev)
break;
}
}
+
+   /*
+* Disable tuner to demod link to avoid disable step
+* when tuner is requested by video or audio
+   */
+   if (tuner && demod) {
+   struct media_link *link;
+
+   list_for_each_entry(link, >links, list) {
+   if (link->sink->entity == demod &&
+   link->source->entity == tuner) {
+   media_entity_setup_link(link, 0);
+   }
+   }
+   }
 #endif
return 0;
 }
-- 
2.5.0



[PATCH v2 19/22] media: au0828-core register entity_notify hook

2016-02-03 Thread Shuah Khan
Register entity_notify async hook to create links
between existing bridge driver entities and a newly
added non-bridge driver entities. For example, this
handler creates link between V4L decoder entity and
ALSA mixer entity.

Signed-off-by: Shuah Khan 
---
 drivers/media/usb/au0828/au0828-core.c | 43 --
 drivers/media/usb/au0828/au0828.h  |  1 +
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-core.c 
b/drivers/media/usb/au0828/au0828-core.c
index 92d22ed..4c90f28 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -347,14 +347,42 @@ static int au0828_create_media_graph(struct au0828_dev 
*dev)
return 0;
 }
 
+void au0828_media_graph_notify(struct media_entity *new, void *notify_data)
+{
+#ifdef CONFIG_MEDIA_CONTROLLER
+   struct au0828_dev *dev = (struct au0828_dev *) notify_data;
+   int ret;
+
+   if (!dev->decoder)
+   return;
+
+   switch (new->function) {
+   case MEDIA_ENT_F_AUDIO_MIXER:
+   ret = media_create_pad_link(dev->decoder,
+   AU8522_PAD_AUDIO_OUT,
+   new, 0,
+   MEDIA_LNK_FL_ENABLED);
+   if (ret)
+   dev_err(>usbdev->dev,
+   "Mixer Pad Link Create Error: %d\n",
+   ret);
+   break;
+   default:
+   break;
+   }
+#endif
+}
+
 static int au0828_media_device_register(struct au0828_dev *dev,
struct usb_device *udev)
 {
 #ifdef CONFIG_MEDIA_CONTROLLER
int ret;
 
-   if (dev->media_dev &&
-   !media_devnode_is_registered(>media_dev->devnode)) {
+   if (!dev->media_dev)
+   return 0;
+
+   if (!media_devnode_is_registered(>media_dev->devnode)) {
 
/* register media device */
ret = media_device_register(dev->media_dev);
@@ -364,6 +392,17 @@ static int au0828_media_device_register(struct au0828_dev 
*dev,
return ret;
}
}
+   /* register entity_notify callback */
+   dev->entity_notify.notify_data = (void *) dev;
+   dev->entity_notify.notify = (void *) au0828_media_graph_notify;
+   ret = media_device_register_entity_notify(dev->media_dev,
+ >entity_notify);
+   if (ret) {
+   dev_err(>dev,
+   "Media Device register entity_notify Error: %d\n",
+   ret);
+   return ret;
+   }
 #endif
return 0;
 }
diff --git a/drivers/media/usb/au0828/au0828.h 
b/drivers/media/usb/au0828/au0828.h
index 8276072..54379ec 100644
--- a/drivers/media/usb/au0828/au0828.h
+++ b/drivers/media/usb/au0828/au0828.h
@@ -283,6 +283,7 @@ struct au0828_dev {
struct media_entity *decoder;
struct media_entity input_ent[AU0828_MAX_INPUT];
struct media_pad input_pad[AU0828_MAX_INPUT];
+   struct media_entity_notify entity_notify;
 #endif
 };
 
-- 
2.5.0



[PATCH v2 14/22] media: au0828 change to use Managed Media Controller API

2016-02-03 Thread Shuah Khan
Change au0828 to use Managed Media Controller API to
share media device and coordinate creating/deleting
the shared media device with the snd-usb-audio driver.
The shared media device is created as device resource
of the parent usb device of the two drivers.

Signed-off-by: Shuah Khan 
---
 drivers/media/usb/au0828/au0828-core.c | 29 +++--
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-core.c 
b/drivers/media/usb/au0828/au0828-core.c
index df2bc3f..b8c4bdd 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -134,10 +134,10 @@ static void au0828_unregister_media_device(struct 
au0828_dev *dev)
 {
 
 #ifdef CONFIG_MEDIA_CONTROLLER
-   if (dev->media_dev) {
+   if (dev->media_dev &&
+   media_devnode_is_registered(>media_dev->devnode)) {
media_device_unregister(dev->media_dev);
media_device_cleanup(dev->media_dev);
-   kfree(dev->media_dev);
dev->media_dev = NULL;
}
 #endif
@@ -223,23 +223,24 @@ static int au0828_media_device_init(struct au0828_dev 
*dev,
 #ifdef CONFIG_MEDIA_CONTROLLER
struct media_device *mdev;
 
-   mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
+   mdev = media_device_get_devres(>dev);
if (!mdev)
return -ENOMEM;
 
-   mdev->dev = >dev;
+   if (!media_devnode_is_registered(>devnode)) {
+   mdev->dev = >dev;
 
-   if (!dev->board.name)
-   strlcpy(mdev->model, "unknown au0828", sizeof(mdev->model));
-   else
-   strlcpy(mdev->model, dev->board.name, sizeof(mdev->model));
-   if (udev->serial)
-   strlcpy(mdev->serial, udev->serial, sizeof(mdev->serial));
-   strcpy(mdev->bus_info, udev->devpath);
-   mdev->hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
-   mdev->driver_version = LINUX_VERSION_CODE;
+   if (udev->product)
+   strlcpy(mdev->model, udev->product,
+   sizeof(mdev->model));
+   if (udev->serial)
+   strlcpy(mdev->serial, udev->serial,
+   sizeof(mdev->serial));
+   strcpy(mdev->bus_info, udev->devpath);
+   mdev->hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
 
-   media_device_init(mdev);
+   media_device_init(mdev);
+   }
 
dev->media_dev = mdev;
 #endif
-- 
2.5.0



[PATCH v2 18/22] media: au0828 Use au8522_media_pads enum for pad defines

2016-02-03 Thread Shuah Khan
Change au0828-core to use au8522_media_pads enum defines
instead of hard-coding the pad values.

Signed-off-by: Shuah Khan 
---
 drivers/media/usb/au0828/au0828-core.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-core.c 
b/drivers/media/usb/au0828/au0828-core.c
index b02a122..92d22ed 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -20,6 +20,7 @@
  */
 
 #include "au0828.h"
+#include "au8522.h"
 
 #include 
 #include 
@@ -287,11 +288,13 @@ static int au0828_create_media_graph(struct au0828_dev 
*dev)
if (ret)
return ret;
}
-   ret = media_create_pad_link(decoder, 1, >vdev.entity, 0,
+   ret = media_create_pad_link(decoder, AU8522_PAD_VID_OUT,
+   >vdev.entity, 0,
MEDIA_LNK_FL_ENABLED);
if (ret)
return ret;
-   ret = media_create_pad_link(decoder, 2, >vbi_dev.entity, 0,
+   ret = media_create_pad_link(decoder, AU8522_PAD_VBI_OUT,
+   >vbi_dev.entity, 0,
MEDIA_LNK_FL_ENABLED);
if (ret)
return ret;
-- 
2.5.0



[PATCH v2 15/22] media: au0828 handle media_init and media_register window

2016-02-03 Thread Shuah Khan
Media device initialization and registration
steps are split. There is a window between
media device init and media device register
during usb probe.

au0828 bridge driver and snd-usb-audio could
try to initialize the media device, if they
simply checked, whether the device has been
registered. They also need to check whether
the device has been initialized.

Change the au0828-core to check if media device
is already initialized during initialization step
and check if media device is already registered
during the registration step.

Signed-off-by: Shuah Khan 
---
 drivers/media/usb/au0828/au0828-core.c | 26 --
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-core.c 
b/drivers/media/usb/au0828/au0828-core.c
index b8c4bdd..e43618d 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -227,7 +227,8 @@ static int au0828_media_device_init(struct au0828_dev *dev,
if (!mdev)
return -ENOMEM;
 
-   if (!media_devnode_is_registered(>devnode)) {
+   /* check if media device is already initialized */
+   if (!mdev->dev) {
mdev->dev = >dev;
 
if (udev->product)
@@ -325,6 +326,27 @@ static int au0828_create_media_graph(struct au0828_dev 
*dev)
return 0;
 }
 
+static int au0828_media_device_register(struct au0828_dev *dev,
+   struct usb_device *udev)
+{
+#ifdef CONFIG_MEDIA_CONTROLLER
+   int ret;
+
+   if (dev->media_dev &&
+   !media_devnode_is_registered(>media_dev->devnode)) {
+
+   /* register media device */
+   ret = media_device_register(dev->media_dev);
+   if (ret) {
+   dev_err(>dev,
+   "Media Device Register Error: %d\n", ret);
+   return ret;
+   }
+   }
+#endif
+   return 0;
+}
+
 static int au0828_usb_probe(struct usb_interface *interface,
const struct usb_device_id *id)
 {
@@ -452,7 +474,7 @@ static int au0828_usb_probe(struct usb_interface *interface,
}
 
 #ifdef CONFIG_MEDIA_CONTROLLER
-   retval = media_device_register(dev->media_dev);
+   retval = au0828_media_device_register(dev, usbdev);
 #endif
 
 done:
-- 
2.5.0



[PATCH v2 21/22] sound/usb: Use Media Controller API to share media resources

2016-02-03 Thread Shuah Khan
Change ALSA driver to use Media Controller API to
share media resources with DVB and V4L2 drivers
on a AU0828 media device. Media Controller specific
initialization is done after sound card is registered.
ALSA creates Media interface and entity function graph
nodes for Control, Mixer, PCM Playback, and PCM Capture
devices.

snd_usb_hw_params() will call Media Controller enable
source handler interface to request the media resource.
If resource request is granted, it will release it from
snd_usb_hw_free(). If resource is busy, -EBUSY is returned.

Media specific cleanup is done in usb_audio_disconnect().

Signed-off-by: Shuah Khan 
---
 sound/usb/Kconfig|   4 +
 sound/usb/Makefile   |   2 +
 sound/usb/card.c |  14 +++
 sound/usb/card.h |   1 +
 sound/usb/media.c| 319 +++
 sound/usb/media.h|  72 +++
 sound/usb/mixer.h|   1 +
 sound/usb/pcm.c  |  28 -
 sound/usb/quirks-table.h |   1 +
 sound/usb/stream.c   |   2 +
 sound/usb/usbaudio.h |   3 +
 11 files changed, 442 insertions(+), 5 deletions(-)
 create mode 100644 sound/usb/media.c
 create mode 100644 sound/usb/media.h

diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig
index a452ad7..1a71d93 100644
--- a/sound/usb/Kconfig
+++ b/sound/usb/Kconfig
@@ -15,6 +15,7 @@ config SND_USB_AUDIO
select SND_RAWMIDI
select SND_PCM
select BITREVERSE
+   select SND_USB_AUDIO_USE_MEDIA_CONTROLLER   if MEDIA_CONTROLLER
help
  Say Y here to include support for USB audio and USB MIDI
  devices.
@@ -22,6 +23,9 @@ config SND_USB_AUDIO
  To compile this driver as a module, choose M here: the module
  will be called snd-usb-audio.
 
+config SND_USB_AUDIO_USE_MEDIA_CONTROLLER
+   bool
+
 config SND_USB_UA101
tristate "Edirol UA-101/UA-1000 driver"
select SND_PCM
diff --git a/sound/usb/Makefile b/sound/usb/Makefile
index 2d2d122..8dca3c4 100644
--- a/sound/usb/Makefile
+++ b/sound/usb/Makefile
@@ -15,6 +15,8 @@ snd-usb-audio-objs := card.o \
quirks.o \
stream.o
 
+snd-usb-audio-$(CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER) += media.o
+
 snd-usbmidi-lib-objs := midi.o
 
 # Toplevel Module Dependency
diff --git a/sound/usb/card.c b/sound/usb/card.c
index 1f09d95..35fe256 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -66,6 +66,7 @@
 #include "format.h"
 #include "power.h"
 #include "stream.h"
+#include "media.h"
 
 MODULE_AUTHOR("Takashi Iwai ");
 MODULE_DESCRIPTION("USB Audio");
@@ -561,6 +562,11 @@ static int usb_audio_probe(struct usb_interface *intf,
if (err < 0)
goto __error;
 
+   if (quirk->media_device) {
+   /* don't want to fail when media_device_create() fails */
+   media_device_create(chip, intf);
+   }
+
usb_chip[chip->index] = chip;
chip->num_interfaces++;
usb_set_intfdata(intf, chip);
@@ -617,6 +623,14 @@ static void usb_audio_disconnect(struct usb_interface 
*intf)
list_for_each(p, >midi_list) {
snd_usbmidi_disconnect(p);
}
+   /*
+* Nice to check quirk && quirk->media_device
+* need some special handlings. Doesn't look like
+* we have access to quirk here
+* Acceses mixer_list
+   */
+   media_device_delete(chip);
+
/* release mixer resources */
list_for_each_entry(mixer, >mixer_list, list) {
snd_usb_mixer_disconnect(mixer);
diff --git a/sound/usb/card.h b/sound/usb/card.h
index 71778ca..c15a03c 100644
--- a/sound/usb/card.h
+++ b/sound/usb/card.h
@@ -156,6 +156,7 @@ struct snd_usb_substream {
} dsd_dop;
 
bool trigger_tstamp_pending_update; /* trigger timestamp being updated 
from initial estimate */
+   void *media_ctl;
 };
 
 struct snd_usb_stream {
diff --git a/sound/usb/media.c b/sound/usb/media.c
new file mode 100644
index 000..8fef48e
--- /dev/null
+++ b/sound/usb/media.c
@@ -0,0 +1,319 @@
+/*
+ * media.c - Media Controller specific ALSA driver code
+ *
+ * Copyright (c) 2015 Shuah Khan 
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * This file is released under the GPLv2.
+ */
+
+/*
+ * This file adds Media Controller support to ALSA driver
+ * to use the Media Controller API to share tuner with DVB
+ * and V4L2 drivers that control media device. Media device
+ * is created based on existing quirks framework. Using this
+ * approach, the media controller API usage can be added for
+ * a specific device.
+*/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include "usbaudio.h"
+#include "card.h"
+#include "mixer.h"
+#include "media.h"
+
+static int media_enable_source(struct media_ctl *mctl)
+{
+   if (mctl && 

[PATCH v2 20/22] media: au0828 add enable, disable source handlers

2016-02-03 Thread Shuah Khan
Add enable_source and disable_source handlers.
The enable source handler is called from
v4l2-core, dvb-core, and ALSA drivers to check
if the shared media source is free. The disable
source handler is called to release the shared
media source.

Signed-off-by: Shuah Khan 
---
 drivers/media/usb/au0828/au0828-core.c | 149 +
 drivers/media/usb/au0828/au0828.h  |   3 +
 2 files changed, 152 insertions(+)

diff --git a/drivers/media/usb/au0828/au0828-core.c 
b/drivers/media/usb/au0828/au0828-core.c
index 4c90f28..fd2265c 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -282,6 +282,7 @@ static int au0828_create_media_graph(struct au0828_dev *dev)
return -EINVAL;
 
if (tuner) {
+   dev->tuner = tuner;
/* create tuner to decoder link in deactivated state */
ret = media_create_pad_link(tuner, TUNER_PAD_OUTPUT,
decoder, 0, 0);
@@ -373,6 +374,150 @@ void au0828_media_graph_notify(struct media_entity *new, 
void *notify_data)
 #endif
 }
 
+static int au0828_enable_source(struct media_entity *entity,
+   struct media_pipeline *pipe)
+{
+#ifdef CONFIG_MEDIA_CONTROLLER
+   struct media_entity  *source;
+   struct media_entity *sink;
+   struct media_link *link, *found_link = NULL;
+   int ret = 0;
+   struct media_device *mdev = entity->graph_obj.mdev;
+   struct au0828_dev *dev;
+
+   if (!mdev)
+   return -ENODEV;
+
+   /* for Audio and Video entities, source is the decoder */
+   mutex_lock(>graph_mutex);
+
+   dev = mdev->source_priv;
+   if (!dev->tuner || !dev->decoder) {
+   ret = -ENODEV;
+   goto end;
+   }
+
+   /*
+* For Audio and V4L2 entity, find the link to which decoder
+* is the sink. Look for an active link between decoder and
+* tuner, if one exists, nothing to do. If not, look for any
+* active links between tuner and any other entity. If one
+* exists, tuner is busy. If tuner is free, setup link and
+* start pipeline from source (tuner).
+* For DVB FE entity, the source for the link is the tuner.
+* Check if tuner is available and setup link and start
+* pipeline.
+   */
+   if (entity->function != MEDIA_ENT_F_DTV_DEMOD)
+   sink = dev->decoder;
+   else
+   sink = entity;
+
+   /* Is an active link between sink and tuner */
+   if (dev->active_link) {
+   if (dev->active_link->sink->entity == sink &&
+   dev->active_link->source->entity == dev->tuner) {
+   ret = 0;
+   goto end;
+   } else {
+   ret = -EBUSY;
+   goto end;
+   }
+   }
+
+   list_for_each_entry(link, >links, list) {
+   /* Check sink, and source */
+   if (link->sink->entity == sink &&
+   link->source->entity == dev->tuner) {
+   found_link = link;
+   break;
+   }
+   }
+
+   if (!found_link) {
+   ret = -ENODEV;
+   goto end;
+   }
+
+   /* activate link between source and sink and start pipeline */
+   source = found_link->source->entity;
+   ret = __media_entity_setup_link(found_link, MEDIA_LNK_FL_ENABLED);
+   if (ret) {
+   pr_err(
+   "Activate tuner link %s->%s. Error %d\n",
+   source->name, sink->name, ret);
+   goto end;
+   }
+
+   ret = __media_entity_pipeline_start(entity, pipe);
+   if (ret) {
+   pr_err("Start Pipeline: %s->%s Error %d\n",
+   source->name, entity->name, ret);
+   ret = __media_entity_setup_link(found_link, 0);
+   pr_err("Deactive link Error %d\n", ret);
+   goto end;
+   }
+   /*
+* save active link and active link owner to avoid audio
+* deactivating video owned link from disable_source and
+* vice versa
+   */
+   dev->active_link = found_link;
+   dev->active_link_owner = entity;
+end:
+   mutex_unlock(>graph_mutex);
+   pr_debug("au0828_enable_source() end %s %d %d\n",
+   entity->name, entity->function, ret);
+   return ret;
+#endif
+   return 0;
+}
+
+static void au0828_disable_source(struct media_entity *entity)
+{
+#ifdef CONFIG_MEDIA_CONTROLLER
+   struct media_entity *sink;
+   int ret = 0;
+   struct media_device *mdev = entity->graph_obj.mdev;
+   struct au0828_dev *dev;
+
+   if (!mdev)
+   return;
+
+   mutex_lock(>graph_mutex);
+   dev = mdev->source_priv;
+   if (!dev->tuner || !dev->decoder || !dev->active_link) {
+  

[PATCH v2 16/22] media: au0828 create tuner to decoder link in disabled state

2016-02-03 Thread Shuah Khan
Create tuner to demod pad link in disabled state to
avoid disable step when tuner resource is requested
by dvb.

Signed-off-by: Shuah Khan 
---
 drivers/media/usb/au0828/au0828-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-core.c 
b/drivers/media/usb/au0828/au0828-core.c
index e43618d..868babe 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -278,9 +278,9 @@ static int au0828_create_media_graph(struct au0828_dev *dev)
return -EINVAL;
 
if (tuner) {
+   /* create tuner to decoder link in deactivated state */
ret = media_create_pad_link(tuner, TUNER_PAD_OUTPUT,
-   decoder, 0,
-   MEDIA_LNK_FL_ENABLED);
+   decoder, 0, 0);
if (ret)
return ret;
}
-- 
2.5.0



[PATCH v2 22/22] media: Ensure media device unregister is done only once

2016-02-03 Thread Shuah Khan
media_device_unregister() checks if the media device
is registered or not as the first step. However, the
MEDIA_FLAG_REGISTERED bit doesn't get cleared until
the end leaving a large window for two drivers to
attempt media device unregister.

The above leads to general protection faults when
device is removed.

Fix the problem with two phase media device unregister.
Add a new interface media_devnode_start_unregister()
to clear the MEDIA_FLAG_REGISTERED bit. Change
media_device_unregister() call this interface to mark
the start of unregister. This will ensure that media
device unregister is done only once.

Signed-off-by: Shuah Khan 
---
 drivers/media/media-device.c  | 12 ++--
 drivers/media/media-devnode.c | 15 ++-
 include/media/media-devnode.h | 17 +
 3 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 1f5d67e..584d46e 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -747,17 +747,17 @@ void media_device_unregister(struct media_device *mdev)
struct media_entity *next;
struct media_interface *intf, *tmp_intf;
struct media_entity_notify *notify, *nextp;
+   int ret;
 
if (mdev == NULL)
return;
 
-   spin_lock(>lock);
-
-   /* Check if mdev was ever registered at all */
-   if (!media_devnode_is_registered(>devnode)) {
-   spin_unlock(>lock);
+   /* Start unregister - continue if necessary */
+   ret = media_devnode_start_unregister(>devnode);
+   if (ret)
return;
-   }
+
+   spin_lock(>lock);
 
/* Remove all entities from the media device */
list_for_each_entry_safe(entity, next, >entities, graph_obj.list)
diff --git a/drivers/media/media-devnode.c b/drivers/media/media-devnode.c
index 29409f4..c27f9e7 100644
--- a/drivers/media/media-devnode.c
+++ b/drivers/media/media-devnode.c
@@ -272,15 +272,20 @@ error:
return ret;
 }
 
-void media_devnode_unregister(struct media_devnode *mdev)
+int __must_check media_devnode_start_unregister(struct media_devnode *mdev)
 {
-   /* Check if mdev was ever registered at all */
-   if (!media_devnode_is_registered(mdev))
-   return;
-
mutex_lock(_devnode_lock);
+   if (!media_devnode_is_registered(mdev)) {
+   mutex_unlock(_devnode_lock);
+   return -EINVAL;
+   }
clear_bit(MEDIA_FLAG_REGISTERED, >flags);
mutex_unlock(_devnode_lock);
+   return 0;
+}
+
+void media_devnode_unregister(struct media_devnode *mdev)
+{
device_unregister(>dev);
 }
 
diff --git a/include/media/media-devnode.h b/include/media/media-devnode.h
index fe42f08..6f08677 100644
--- a/include/media/media-devnode.h
+++ b/include/media/media-devnode.h
@@ -120,6 +120,23 @@ int __must_check media_devnode_register(struct 
media_devnode *mdev,
struct module *owner);
 
 /**
+ * media_devnode_start_unregister - start unregister on a media device node
+ * @mdev: the device node to start unregister
+ *
+ * This clears the MEDIA_FLAG_REGISTERED bit to indicate that unregister
+ * is in progress.
+ *
+ * This function can safely be called if the device node has never been
+ * registered or has already been unregistered.
+ *
+ * Zero is returned on success.
+ *
+ * -EINVAL is returned if the device node has never been
+ * registered or has already been unregistered.
+ */
+int __must_check media_devnode_start_unregister(struct media_devnode *mdev);
+
+/**
  * media_devnode_unregister - unregister a media device node
  * @mdev: the device node to unregister
  *
-- 
2.5.0



[PATCH v2 05/22] media: Media Controller export non locking __media_entity_setup_link()

2016-02-03 Thread Shuah Khan
Export __media_entity_setup_link() to be used from code paths
that hold the graph_mutex.

Signed-off-by: Shuah Khan 
---
 drivers/media/media-entity.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 6179543..9b4d712 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -805,6 +805,7 @@ int __media_entity_setup_link(struct media_link *link, u32 
flags)
 
return ret;
 }
+EXPORT_SYMBOL_GPL(__media_entity_setup_link);
 
 int media_entity_setup_link(struct media_link *link, u32 flags)
 {
-- 
2.5.0



[PATCH v2 02/22] media: Add ALSA Media Controller function entities

2016-02-03 Thread Shuah Khan
Add ALSA Media Controller capture, playback, and mixer
function entity defines.

Signed-off-by: Shuah Khan 
---
 include/uapi/linux/media.h | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index ee020e8..7d50480 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -98,6 +98,17 @@ struct media_device_info {
 #define MEDIA_ENT_F_IF_AUD_DECODER (MEDIA_ENT_F_BASE + 42)
 
 /*
+ * DOC: Media Controller Next Generation ALSA Function Entities
+ *
+ * MEDIA_ENT_F_AUDIO_CAPTURE - Audio Capture Function
+ * MEDIA_ENT_F_AUDIO_PLAYBACK - Audio Play Back Function
+ * MEDIA_ENT_F_AUDIO_MIXER - Audio Mixer Function
+*/
+#define MEDIA_ENT_F_AUDIO_CAPTURE  (MEDIA_ENT_F_BASE + 200)
+#define MEDIA_ENT_F_AUDIO_PLAYBACK (MEDIA_ENT_F_BASE + 201)
+#define MEDIA_ENT_F_AUDIO_MIXER(MEDIA_ENT_F_BASE + 202)
+
+/*
  * Don't touch on those. The ranges MEDIA_ENT_F_OLD_BASE and
  * MEDIA_ENT_F_OLD_SUBDEV_BASE are kept to keep backward compatibility
  * with the legacy v1 API.The number range is out of range by purpose:
-- 
2.5.0



Re: [PATCH v2] arm64: defconfig: Enable samsung MFD and related configs

2016-02-03 Thread Alim Akhtar



On 11/06/2015 10:07 PM, Catalin Marinas wrote:

On Fri, Nov 06, 2015 at 02:47:12PM +0900, Krzysztof Kozlowski wrote:

2015-11-06 14:27 GMT+09:00 Alim Akhtar :

Exynos7 based espresso board uses S2MPS15, a multifunction device.
This patch enables S2MPS1X regulator, pmic-clk and rtc drivers utilized by
the same.

Signed-off-by: Alim Akhtar 
---
Changes since v1:
* updated the comment message to describe which platfrom uses it.
* enable COMMON_CLK_S2MPS11 which is needed to enable pmic-clk block.

  arch/arm64/configs/defconfig |4 
  1 file changed, 4 insertions(+)


Reviewed-by: Krzysztof Kozlowski 

Catalin,

Are you usually taking such arm64 defconfig changes or should they go
through arm-soc?


Usually arm-soc but I don't mind either way.

Looks like this patch is not merged...because of this 4.5-rc1 on 
exynos7-esspreso does not boot to user space.

Do I need to resend this patch?

Regards,
Alim


Re: [PATCH v2 04/10] crypto/compress: add asynchronous compression support

2016-02-03 Thread Li, Weigang

On 2/4/2016 11:29 AM, Herbert Xu wrote:

On Thu, Feb 04, 2016 at 11:28:50AM +0800, Herbert Xu wrote:

On Thu, Feb 04, 2016 at 11:25:27AM +0800, Li, Weigang wrote:


Please can you advise how to get the acomp patch accepted?


Can you do a posting of these patches without scomp so we can
evaluate the effects?


Of course you can keep the driver-side scomp interface as otherwise
the implementation would be unnecessarily complicated.

Cheers,

Seems I need go back to my first acomp patch.. Assuming we shall still 
keep the comp i/f, and the linearisation of sg-list in acomp to fit the 
"comp" API? What do you mean by the driver-side scomp? Thanks!


linux-next: Tree for Feb 4

2016-02-03 Thread Stephen Rothwell
Hi all,

Changes since 20160203:

The gpio tree still had its build failure so I used the version from
next-20160128.

The aio tree still had a build failure so I used the version from
next-20160111.

The akpm-current tree lost its build failures.

Non-merge commits (relative to Linus' tree): 2245
 2187 files changed, 81671 insertions(+), 36219 deletions(-)



I have created today's linux-next tree at
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
(patches at http://www.kernel.org/pub/linux/kernel/next/ ).  If you
are tracking the linux-next tree using git, you should not use "git pull"
to do so as that will try to merge the new linux-next release with the
old one.  You should use "git fetch" and checkout or reset to the new
master.

You can see which trees have been included by looking in the Next/Trees
file in the source.  There are also quilt-import.log and merge.log
files in the Next directory.  Between each merge, the tree was built
with a ppc64_defconfig for powerpc and an allmodconfig (with
CONFIG_BUILD_DOCSRC=n) for x86_64, a multi_v7_defconfig for arm and a
native build of tools/perf. After the final fixups (if any), I do an
x86_64 modules_install followed by builds for x86_64 allnoconfig,
powerpc allnoconfig (32 and 64 bit), ppc44x_defconfig, allyesconfig
(this fails its final link) and pseries_le_defconfig and i386, sparc
and sparc64 defconfig.

Below is a summary of the state of the merge.

I am currently merging 239 trees (counting Linus' and 36 trees of patches
pending for Linus' tree).

Stats about the size of the tree over time can be seen at
http://neuling.org/linux-next-size.html .

Status of my local build tests will be at
http://kisskb.ellerman.id.au/linux-next .  If maintainers want to give
advice about cross compilers/configs that work, we are always open to add
more builds.

Thanks to Randy Dunlap for doing many randconfig builds.  And to Paul
Gortmaker for triage and bug fixes.

-- 
Cheers,
Stephen Rothwell

$ git checkout master
$ git reset --hard stable
Merging origin/master (b37a05c083c8 Merge branch 'akpm' (patches from Andrew))
Merging fixes/master (92e963f50fc7 Linux 4.5-rc1)
Merging kbuild-current/rc-fixes (3d1450d54a4f Makefile: Force gzip and xz on 
module install)
Merging arc-current/for-curr (74bf8efb5fa6 Linux 4.4-rc7)
Merging arm-current/fixes (03590cb56d5d ARM: wire up copy_file_range() syscall)
Merging m68k-current/for-linus (daf670bc9d36 m68k/defconfig: Update defconfigs 
for v4.5-rc1)
Merging metag-fixes/fixes (0164a711c97b metag: Fix ioremap_wc/ioremap_cached 
build errors)
Merging mips-fixes/mips-fixes (1795cd9b3a91 Linux 3.16-rc5)
Merging powerpc-fixes/fixes (19f97c983071 powerpc/book3s_32: Fix build error 
with checkpoint restart)
Merging powerpc-merge-mpe/fixes (bc0195aad0da Linux 4.2-rc2)
Merging sparc/master (ca0bb0798022 Add sun4v_wdt watchdog driver)
Merging net/master (34229b277480 Merge 
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net)
Merging ipsec/master (a8a572a6b5f2 xfrm: dst_entries_init() per-net dst_ops)
Merging ipvs/master (b16c29191dc8 netfilter: nf_conntrack: use safer way to 
lock all buckets)
Merging wireless-drivers/master (f9ead9beef3f Merge tag 
'iwlwifi-for-kalle-2016-01-26_2' of 
https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/iwlwifi-fixes)
Merging mac80211/master (212c5a5e6ba6 mac80211: minstrel: Change expected 
throughput unit back to Kbps)
Merging sound-current/for-linus (2e5dc73fe1c4 Merge branch 'topic/core-fixes' 
into for-linus)
Merging pci-current/for-linus (46560388c476 PCI: iproc: Allow multiple devices 
except on PAXC)
Merging driver-core.current/driver-core-linus (36f90b0a2ddd Linux 4.5-rc2)
Merging tty.current/tty-linus (36f90b0a2ddd Linux 4.5-rc2)
Merging usb.current/usb-linus (5c82171167ad xhci: Fix list corruption in urb 
dequeue at host removal)
Merging usb-gadget-fixes/fixes (6a4290cc28be usb: dwc3: gadget: set the OTG 
flag in dwc3 gadget driver.)
Merging usb-serial-fixes/usb-linus (4152b387da81 USB: option: fix Cinterion 
AHxx enumeration)
Merging usb-chipidea-fixes/ci-for-usb-stable (6f51bc340d2a usb: chipidea: imx: 
fix a possible NULL dereference)
Merging staging.current/staging-linus (5982557ac6ee Merge tag 
'iio-fixes-for-4.5b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio 
into staging-linus)
Merging char-misc.current/char-misc-linus (92e963f50fc7 Linux 4.5-rc1)
Merging input-current/for-linus (d4f1b06d685d Input: vmmouse - fix absolute 
device registration)
Merging crypto-current/master (49a20454e0eb crypto: atmel-aes - remove calls of 
clk_prepare() from atomic contexts)
Merging ide/master (e04a2bd6d8c9 drivers/ide: make ide-scan-pci.c driver 
explicitly non-modular)
Merging devicetree-current/devicetree/merge (f76502aa9140 of/dynamic: Fix test 
for PPC_PSERIES)
Merging rr-fixes/fixes (275d7d44d802 module: Fix locking in symbol_put_addr())
Merging vfio-fixes/for-linu

  1   2   3   4   5   6   7   8   9   10   >