5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
23 - name: Get CPU topology.
25 var: ncir_cpu_topology
27 var: ncir_cpu_topology
29 - name: Make default performance profile.
32 platform_cpus: "{{ ncir_cpu_topology | cpu_topology_defaults(hosts[hostname]['service_profiles'], ncir_default_platform_cpus, virtual_env, hosts | length < 2) }}"
37 - name: Get performance profile.
39 perf_profile: "{{ perf_profile | combine(performance_profiles[hosts[hostname]['performance_profiles'][0]]) }}"
40 when: "'performance_profiles' in hosts[hostname]"
44 - name: Make CPU sets.
45 include_tasks: make_cpu_sets.yaml
49 - { 'name': 'ovs_dpdk', 'opt': "{{ cpu_set_mapping['ovs_dpdk']['opt'] }}", 'where': 'tail' }
50 - { 'name': 'platform', 'opt': "{{ cpu_set_mapping['platform']['opt'] }}", 'where': 'head' }
51 when: "cpu_set.opt in perf_profile"
53 - name: Initialize VM CPU share.
57 - name: Set collocated VM CPU set.
59 vm_share_percent: "{{ 100 - (perf_profile['caas_cpu_pool_share'] | default(100) | int) }}"
61 - "'compute' in hosts[hostname]['service_profiles']"
62 - hosts[hostname]['service_profiles'] | intersect(caas_service_profiles)
64 - name: Make VM CPU sets.
65 include_tasks: make_cpu_sets.yaml
69 - { 'name': 'vm', 'request': "{{ ncir_cpu_topology | get_cpu_count_by_percent(vm_share_percent) }}", 'where': 'tail' }
71 - "'compute' in hosts[hostname]['service_profiles']"
73 - name: Calculate CaaS CPU counts
75 perf_profile: "{{ perf_profile | combine({ item.key: ncir_cpu_topology | get_cpu_count_by_percent(item.value) }) }}"
76 with_dict: "{{ perf_profile['caas_cpu_pools'] | default({}) }}"
77 when: hosts[hostname]['service_profiles'] | intersect(caas_service_profiles)
79 - name: Make CaaS CPU sets.
80 include_tasks: make_cpu_sets.yaml
84 - { 'name': 'caas_exclusive', 'opt': "{{ cpu_set_mapping['caas_exclusive']['opt'] }}", 'where': 'tail' }
85 - { 'name': 'caas_shared', 'opt': "{{ cpu_set_mapping['caas_shared']['opt'] }}", 'where': 'tail' }
87 - "cpu_set.opt in perf_profile"
88 - hosts[hostname]['service_profiles'] | intersect(caas_service_profiles)
90 - name: Make set of remaining CPUs.
92 ncir_cpu_remain: "{{ ncir_cpu_remain | union(item) }}"
93 with_items: "{{ ncir_cpu_topology.values() }}"
97 - name: Allocate remaining CPUs to platform.
99 ncir_cpu_sets: "{{ ncir_cpu_sets | combine({ 'platform': ncir_cpu_sets['platform'] | default([]) | union(ncir_cpu_remain) }) }}"
101 when: "ncir_cpu_remain | length > 0"
106 - name: Make sure facts directory exists.
108 path: "{{ allocation_fact_file | dirname }}"
112 - name: Save CPU allocation.
114 src: ncir_cpu_allocation.fact.j2
115 dest: "{{ allocation_fact_file }}"
116 register: cpu_allocation
118 - name: Refresh facts.
121 - cpu_allocation.changed
122 - not skip_facts_reload | default(False)