ppc64_cpu: test_attr return 2 when file missing

The old logic was to assume the attribute is readable when the sysfs
file does not exist. This makes it hard to detect when subcores are
available.

However, the existing code relies on not returning an error when
iterating through the CPUs in sysfs. Compromise by returning 2, which
doesn't break existing code, and allows new users to ask precisely what
the state of the attribute is.

Signed-off-by: Joel Stanley <joel@jms.id.au>
ppc64_cpu: Add --subcores-per-core option

Upcoming power8 chips support a concept called split core. This is where
the core can be split into subcores that although not full cores, are
able to appear as full cores to a guest.

Currently the kernel supports setting subcores per core to 1 or 4,
through a sysfs interface.

This command allows the split state to be queried, and set to 1 or 4.

Signed-off-by: Joel Stanley <joel@jms.id.au>
ppc64_cpu: Teach all options about subcores

Commands such as --smt=on/off need to know about subcores so they can
online the required threads when a core is in split core mode.

Instead of re-implementing commands so that subcores are treated
correctly, make the entire program treat subcores as cores. This means
that commands such as --cores-on report the number of subcores, not
physical cores.

Signed-off-by: Joel Stanley <joel@jms.id.au>
ppc64_cpu: Core state should depend on all threads

A core should be considered running when any thread is online.  The
previous test only looked at the first thread on a core, now we loop
through all cores in the core in question.

Signed-off-by: Joel Stanley <joel@jms.id.au>
ppc64_cpu: Add --info command

This lists all threads on the system, grouped by the cores they belong
to. The online status of a thread is indicated by an asterisk.

  $ ppc64_cpu --info
  Core   0:    0*    1*    2*    3*    4*    5*    6*    7*
  Core   1:    8*    9*   10*   11*   12*   13*   14*   15*
  Core   2:   16*   17*   18*   19*   20*   21*   22*   23*
  Core   3:   24*   25*   26*   27*   28*   29*   30*   31*

If a system supports subcores, and the user has permission to access the
sysfs files that indicate the subcore status, the threads will be
grouped by subcore.

  $ ppc64_cpu --info
  Core   0:
    Subcore   0:    0*    1
    Subcore   1:    2     3
    Subcore   2:    4     5
    Subcore   3:    6     7
  Core   1:
    Subcore   4:    8*    9
    Subcore   5:   10    11
    Subcore   6:   12    13
    Subcore   7:   14    15

Signed-off-by: Joel Stanley <joel@jms.id.au>
ppc64_cpu: Check {get,set}_attribute return values

Take a look at the return value of the fprintf/scanf, and propagate
the return code. This removes a compiler warning.

Signed-off-by: Joel Stanley <joel@jms.id.au>