4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
22 - name: Get CPU topology.
28 - name: Make default performance profile.
31 platform_cpus: "{{ cpu_topology | cpu_topology_defaults(hosts[hostname]['service_profiles'], platform_cpus, virtual_env, hosts | length < 2) }}"
36 - name: Get performance profile.
38 perf_profile: "{{ perf_profile | combine(performance_profiles[hosts[hostname]['performance_profiles'][0]]) }}"
39 when: "'performance_profiles' in hosts[hostname]"
43 - name: Make CPU sets.
44 include_tasks: make_cpu_sets.yaml
48 - { 'name': 'ovs_dpdk', 'opt': "{{ cpu_set_mapping['ovs_dpdk']['opt'] }}", 'where': 'tail' }
49 - { 'name': 'platform', 'opt': "{{ cpu_set_mapping['platform']['opt'] }}", 'where': 'head' }
50 when: "cpu_set.opt in perf_profile"
52 - name: Initialize VM CPU share.
56 - name: Set collocated VM CPU set.
58 vm_share_percent: "{{ 100 - (perf_profile['caas_cpu_pool_share'] | default(caas_cpu_pool_share_default) | int) }}"
60 - "'compute' in hosts[hostname]['service_profiles']"
61 - hosts[hostname]['service_profiles'] | intersect(caas_service_profiles)
63 - name: Make VM CPU sets.
64 include_tasks: make_cpu_sets.yaml
68 - { 'name': 'vm', 'request': "{{ cpu_topology | get_cpu_count_by_percent(vm_share_percent) }}", 'where': 'tail' }
70 - "'compute' in hosts[hostname]['service_profiles']"
72 - name: Make CaaS default CPU set.
73 include_tasks: make_cpu_sets.yaml
77 - { 'name': 'caas_default', 'request': "{{ cpu_topology | cpu_topology_defaults(hosts[hostname]['service_profiles'], caas_default_pool_cpus, virtual_env, hosts | length < 2) }}", 'where': 'tail' }
79 - hosts[hostname]['service_profiles'] | intersect(caas_service_profiles)
81 - name: Calculate CaaS CPU counts
83 perf_profile: "{{ perf_profile | combine({ item.key: cpu_topology | get_cpu_count_by_percent(item.value) }) }}"
84 with_dict: "{{ perf_profile['caas_cpu_pools'] | default({}) }}"
85 when: hosts[hostname]['service_profiles'] | intersect(caas_service_profiles)
87 - name: Make CaaS CPU sets.
88 include_tasks: make_cpu_sets.yaml
92 - { 'name': 'caas_exclusive', 'opt': "{{ cpu_set_mapping['caas_exclusive']['opt'] }}", 'where': 'tail' }
93 - { 'name': 'caas_shared', 'opt': "{{ cpu_set_mapping['caas_shared']['opt'] }}", 'where': 'tail' }
95 - "cpu_set.opt in perf_profile"
96 - hosts[hostname]['service_profiles'] | intersect(caas_service_profiles)
98 - name: Make set of remaining CPUs.
100 cpu_remain: "{{ cpu_remain | union(item) }}"
101 with_items: "{{ cpu_topology.values() }}"
105 - name: Allocate remaining CPUs to CaaS default.
107 cpu_sets: "{{ cpu_sets | combine({ 'caas_default': cpu_sets['caas_default'] | default([]) | union(cpu_remain) }) }}"
110 - "cpu_remain | length > 0"
111 - hosts[hostname]['service_profiles'] | intersect(caas_service_profiles)
113 - name: Allocate remaining CPUs to platform.
115 cpu_sets: "{{ cpu_sets | combine({ 'platform': cpu_sets['platform'] | default([]) | union(cpu_remain) }) }}"
118 - "cpu_remain | length > 0"
119 - not hosts[hostname]['service_profiles'] | intersect(caas_service_profiles)
124 - name: Make sure facts directory exists.
126 path: "{{ allocation_fact_file | dirname }}"
130 - name: Save CPU allocation.
132 src: cpu_allocation.fact.j2
133 dest: "{{ allocation_fact_file }}"
134 register: cpu_allocation
136 - name: Refresh facts.
139 - cpu_allocation.changed
140 - not skip_facts_reload | default(False)