diff options
author | Robert Jennings <rcj@linux.vnet.ibm.com> | 2008-07-23 14:31:33 -0400 |
---|---|---|
committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2008-07-25 01:44:43 -0400 |
commit | a90ab95a9576d35de0d05f9f4fc435edcccafaa9 (patch) | |
tree | 53824dbf844fafda141e625be3a9d8f3957511e6 /include/asm-powerpc/vio.h | |
parent | 6490c4903d12f242bec4454301f76f6a7520e399 (diff) |
powerpc/pseries: vio bus support for CMO
This is a large patch but the normal code path is not affected. For
non-pSeries platforms the code is ifdef'ed out and for non-CMO enabled
pSeries systems this does not affect the normal code path. Devices that
do not perform DMA operations do not need modification with this patch.
The function get_desired_dma was renamed from get_io_entitlement for
clarity.
Overview
Cooperative Memory Overcommitment (CMO) allows for a set of OS partitions
to be run with less RAM than the aggregate needs of the group of
partitions. The firmware will balance memory between the partitions
and page in/out memory as needed. Based on the number and type of IO
adpaters preset each partition is allocated an amount of memory for
DMA operations and this allocation will be guaranteed to the partition;
this is referred to as the partition's 'entitlement'.
Partitions running in a CMO environment can only have virtual IO devices
present. The VIO bus layer will manage the IO entitlement for the system.
Accounting, at a system and per-device level, is tracked in the VIO bus
code and exposed via sysfs. A set of dma_ops functions are added to
the bus to allow for this accounting.
Bus initialization
At initialization, the bus will calculate the minimum needs of the system
based on providing each device present with a standard minimum entitlement
along with a spare allocation for the bus to handle hotplug events.
If the minimum needs can not be met the system boot will be halted.
Device changes
The significant changes for devices while running under CMO are that the
devices must specify how much dedicated IO entitlement they desire and
must also handle DMA mapping errors that can occur due to constrained
IO memory. The virtual IO drivers are modified to silence errors when
DMA mappings fail for CMO and handle these failures gracefully.
Each devices will be guaranteed a minimum entitlement that can always
be mapped. Devices will specify how much entitlement they desire and
the VIO bus will attempt to provide for this. Devices can change their
desired entitlement level at any point in time to address particular needs
(via vio_cmo_set_dev_desired()), not just at device probe time.
VIO bus changes
The system will have a particular entitlement level available from which
it can provide memory to the devices. The bus defines two pools of memory
within this entitlement, the reserved and excess pools. Each device is
provided with it's own entitlement no less than a system defined minimum
entitlement and no greater than what the device has specified as it's
desired entitlement. The entitlement provided to devices comes from the
reserve pool. The reserve pool can also contain a spare allocation as
large as the system defined minimum entitlement which is used for device
hotplug events. Any entitlement not needed to fulfill the needs of a
reserve pool is placed in the excess pool. Each device is guaranteed
that it can map up to it's entitled level; additional mapping are possible
as long as there is unmapped memory in the excess pool.
Bus probe
As the system starts, each device is given an entitlement equal only
to the system defined minimum entitlement. The reserve pool is equal
to the sum of these entitlements, plus a spare allocation. The VIO bus
also tracks the aggregate desired entitlement of all the devices. If the
system desired entitlement is greater than the size of the reserve pool,
when devices unmap IO memory it will be reserved and a balance operation
will be scheduled for some time in the future.
Entitlement balancing
The balance function tries to fairly distribute entitlement between the
devices in the system with the goal of providing each device with it's
desired amount of entitlement. Devices using more than what would be
ideal will have their entitled set-point adjusted; this will effectively
set a goal for lower IO memory usage as future mappings can fail and
deallocations will trigger a balance operation to distribute the newly
unmapped memory. A fair distribution of entitlement can take several
balance operations to achieve. Entitlement changes and device DLPAR
events will alter the state of CMO and will trigger balance operations.
Hotplug events
The VIO bus allows for changes in system entitlement at run-time via
'vio_cmo_entitlement_update()'. When devices are added the hotplug
device event will be preceded by a system entitlement increase and this
is reversed when devices are removed.
The following changes are made that the VIO bus layer for CMO:
* add IO memory accounting per device structure.
* add IO memory entitlement query function to driver structure.
* during vio bus probe, if CMO is enabled, check that driver has
memory entitlement query function defined. Fail if function not defined.
* fail to register driver if io entitlement function not defined.
* create set of dma_ops at vio level for CMO that will track allocations
and return DMA failures once entitlement is reached. Entitlement will
limited by overall system entitlement. Devices will have a reserved
quantity of memory that is guaranteed, the rest can be used as available.
* expose entitlement, current allocation, desired allocation, and the
allocation error counter for devices to the user through sysfs
* provide mechanism for changing a device's desired entitlement at run time
for devices as an exported function and sysfs tunable
* track any DMA failures for entitled IO memory for each vio device.
* check entitlement against available system entitlement on device add
* track entitlement metrics (high water mark, current usage)
* provide function to reset high water mark
* provide minimum and desired entitlement numbers at a bus level
* provide drivers with a minimum guaranteed entitlement
* balance available entitlement between devices to satisfy their needs
* handle system entitlement changes and device hotplug
Signed-off-by: Robert Jennings <rcj@linux.vnet.ibm.com>
Acked-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'include/asm-powerpc/vio.h')
-rw-r--r-- | include/asm-powerpc/vio.h | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/include/asm-powerpc/vio.h b/include/asm-powerpc/vio.h index 56512a968dab..0a290a195946 100644 --- a/include/asm-powerpc/vio.h +++ b/include/asm-powerpc/vio.h | |||
@@ -39,16 +39,32 @@ | |||
39 | #define VIO_IRQ_DISABLE 0UL | 39 | #define VIO_IRQ_DISABLE 0UL |
40 | #define VIO_IRQ_ENABLE 1UL | 40 | #define VIO_IRQ_ENABLE 1UL |
41 | 41 | ||
42 | /* | ||
43 | * VIO CMO minimum entitlement for all devices and spare entitlement | ||
44 | */ | ||
45 | #define VIO_CMO_MIN_ENT 1562624 | ||
46 | |||
42 | struct iommu_table; | 47 | struct iommu_table; |
43 | 48 | ||
44 | /* | 49 | /** |
45 | * The vio_dev structure is used to describe virtual I/O devices. | 50 | * vio_dev - This structure is used to describe virtual I/O devices. |
51 | * | ||
52 | * @desired: set from return of driver's get_desired_dma() function | ||
53 | * @entitled: bytes of IO data that has been reserved for this device. | ||
54 | * @allocated: bytes of IO data currently in use by the device. | ||
55 | * @allocs_failed: number of DMA failures due to insufficient entitlement. | ||
46 | */ | 56 | */ |
47 | struct vio_dev { | 57 | struct vio_dev { |
48 | const char *name; | 58 | const char *name; |
49 | const char *type; | 59 | const char *type; |
50 | uint32_t unit_address; | 60 | uint32_t unit_address; |
51 | unsigned int irq; | 61 | unsigned int irq; |
62 | struct { | ||
63 | size_t desired; | ||
64 | size_t entitled; | ||
65 | size_t allocated; | ||
66 | atomic_t allocs_failed; | ||
67 | } cmo; | ||
52 | struct device dev; | 68 | struct device dev; |
53 | }; | 69 | }; |
54 | 70 | ||
@@ -56,12 +72,19 @@ struct vio_driver { | |||
56 | const struct vio_device_id *id_table; | 72 | const struct vio_device_id *id_table; |
57 | int (*probe)(struct vio_dev *dev, const struct vio_device_id *id); | 73 | int (*probe)(struct vio_dev *dev, const struct vio_device_id *id); |
58 | int (*remove)(struct vio_dev *dev); | 74 | int (*remove)(struct vio_dev *dev); |
75 | /* A driver must have a get_desired_dma() function to | ||
76 | * be loaded in a CMO environment if it uses DMA. | ||
77 | */ | ||
78 | unsigned long (*get_desired_dma)(struct vio_dev *dev); | ||
59 | struct device_driver driver; | 79 | struct device_driver driver; |
60 | }; | 80 | }; |
61 | 81 | ||
62 | extern int vio_register_driver(struct vio_driver *drv); | 82 | extern int vio_register_driver(struct vio_driver *drv); |
63 | extern void vio_unregister_driver(struct vio_driver *drv); | 83 | extern void vio_unregister_driver(struct vio_driver *drv); |
64 | 84 | ||
85 | extern int vio_cmo_entitlement_update(size_t); | ||
86 | extern void vio_cmo_set_dev_desired(struct vio_dev *viodev, size_t desired); | ||
87 | |||
65 | extern void __devinit vio_unregister_device(struct vio_dev *dev); | 88 | extern void __devinit vio_unregister_device(struct vio_dev *dev); |
66 | 89 | ||
67 | struct device_node; | 90 | struct device_node; |