Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions roles/sap_hana_preconfigure/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,13 @@
- __sap_hana_preconfigure_register_stat_sys_firmware_efi.stat.exists
- sap_hana_preconfigure_run_grub2_mkconfig | d(true)

- name: "Run grubby for enabling TSX"
- name: "Run grubby for configuring kernel command line entries for SAP"
ansible.builtin.command:
cmd: grubby --args="tsx=on" --update-kernel=ALL
cmd: "{{ __sap_hana_preconfigure_fact_grubby_command }}"
changed_when: true
listen: __sap_hana_preconfigure_grubby_update_handler
notify: __sap_hana_preconfigure_reboot_handler

- name: "Run grubby for setting THP to '{{ __sap_hana_preconfigure_fact_thp }}'"
ansible.builtin.command:
cmd: grubby --args="transparent_hugepage={{ __sap_hana_preconfigure_fact_thp }}" --update-kernel=ALL
changed_when: true
listen: __sap_hana_preconfigure_grubby_thp_handler
notify: __sap_hana_preconfigure_reboot_handler

# END - GRUB section


Expand Down
16 changes: 16 additions & 0 deletions roles/sap_hana_preconfigure/tasks/RedHat/configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
ansible.builtin.debug:
var: __sap_hana_preconfigure_sapnotes_versions | difference([''])

- name: Configure - Initialize vars for boot command line updates
ansible.builtin.set_fact:
__sap_hana_preconfigure_boot_command_line_args_final: []
__sap_hana_preconfigure_fact_missing_kernel_args: []
__sap_hana_preconfigure_kernel_args_to_be_updated: []
__sap_hana_preconfigure_fact_kernel_args_to_be_set: []

- name: Configure - Set directory variables for setting SELinux file contexts
ansible.builtin.set_fact:
sap_hana_preconfigure_fact_targets_setypes: "{{ sap_hana_preconfigure_fact_targets_setypes | d([]) +
Expand Down Expand Up @@ -43,3 +50,12 @@
with_items: "{{ __sap_hana_preconfigure_sapnotes_versions | difference(['']) }}"
loop_control:
loop_var: sap_note_line_item

- name: Configure - Initiate GRUB update if necessary
ansible.builtin.include_tasks:
file: "generic/set-boot-kernel-args.yml"
apply:
tags:
- grubconfig
when: __sap_hana_preconfigure_boot_command_line_args_final | length > 0
tags: grubconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
__sap_hana_preconfigure_fact_thp: 'never'
when:
- sap_hana_preconfigure_thp is undefined or sap_hana_preconfigure_thp | length == 0
- ansible_distribution == 'RedHat'
- ansible_distribution_major_version == '7' or
ansible_distribution_major_version == '8' or
ansible_distribution_version == '9.0' or
Expand All @@ -39,10 +38,9 @@
__sap_hana_preconfigure_fact_thp: 'madvise'
when:
- sap_hana_preconfigure_thp is undefined or sap_hana_preconfigure_thp | length == 0
- ansible_distribution == 'RedHat'
- (ansible_distribution_major_version == '9' and
__sap_hana_preconfigure_fact_ansible_distribution_minor_version | int >= 2) or
ansible_distribution_major_version == '10'
- ansible_distribution_major_version | int >= 10 or
(ansible_distribution_major_version == '9' and
__sap_hana_preconfigure_fact_ansible_distribution_minor_version | int >= 2)

- name: Set fact for THP if 'sap_hana_preconfigure_thp' is defined
ansible.builtin.set_fact:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
when:
- ansible_architecture == 'x86_64'
- ansible_distribution == 'RedHat'
- (ansible_distribution_major_version >= '9') or
- ansible_distribution_major_version | int >= 9 or
(ansible_distribution_major_version == '8' and
__sap_hana_preconfigure_fact_ansible_distribution_minor_version | int >= 3)
block:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,13 @@
---

# can be configured by tuned profile sap-hana, entry "force_latency=70"
- name: Configure C-States for lower latency
ansible.builtin.lineinfile:
path: /etc/default/grub
backup: yes
backrefs: yes
state: present
regexp: '^(GRUB_CMDLINE_LINUX=(?!.* {{ line_item }}).*). *$'
line: "\\1 {{ line_item }}\""
with_items:
- "processor.max_cstate=1"
- "intel_idle.max_cstate=1"
notify: __sap_hana_preconfigure_regenerate_grub2_conf_handler
when: ansible_architecture == 'x86_64' and
(not sap_hana_preconfigure_use_tuned or
sap_hana_preconfigure_modify_grub_cmdline_linux)
tags: grubconfig
- name: Add boot command line args for configuring C-States for lower latency
ansible.builtin.set_fact:
__sap_hana_preconfigure_boot_command_line_args_final: >-
{{ __sap_hana_preconfigure_boot_command_line_args_final + [__sap_hana_preconfigure_kernel_arg_line_item] }}
loop: "{{ __sap_hana_preconfigure_boot_command_line_args['c-states']['args'] }}"
loop_control:
loop_var: line_item
loop_var: __sap_hana_preconfigure_kernel_arg_line_item
when:
- __sap_hana_preconfigure_boot_command_line_args['c-states']['arch'] is defined
- ansible_architecture in __sap_hana_preconfigure_boot_command_line_args['c-states']['arch']
91 changes: 39 additions & 52 deletions roles/sap_hana_preconfigure/tasks/RedHat/generic/configure-thp.yml
Original file line number Diff line number Diff line change
@@ -1,63 +1,50 @@
# SPDX-License-Identifier: Apache-2.0
---

- name: Get boot command line
ansible.builtin.slurp:
src: /proc/cmdline
register: __sap_hana_preconfigure_register_proc_cmdline_thp

- name: Set fact for THP, RHEL up to RHEL 9.1
- name: Set fact for THP if 'sap_hana_preconfigure_thp' is defined
ansible.builtin.set_fact:
__sap_hana_preconfigure_fact_thp: 'never'
__sap_hana_preconfigure_fact_thp: "{{ sap_hana_preconfigure_thp }}"
when:
- sap_hana_preconfigure_thp is undefined or sap_hana_preconfigure_thp | length == 0
- ansible_distribution == 'RedHat'
- ansible_distribution_major_version == '7' or
ansible_distribution_major_version == '8' or
ansible_distribution_version == '9.0' or
ansible_distribution_version == '9.1'
- sap_hana_preconfigure_thp is defined
- sap_hana_preconfigure_thp | length > 0

- name: Set fact for THP, RHEL 9.2 and later
- name: Set fact for THP if 'sap_hana_preconfigure_thp' is undefined
ansible.builtin.set_fact:
__sap_hana_preconfigure_fact_thp: 'madvise'
__sap_hana_preconfigure_fact_thp: "{{ __sap_hana_preconfigure_boot_command_line_args['thp']['args'][0].split('=')[1] }}"
when:
- __sap_hana_preconfigure_boot_command_line_args['thp']['arch'] is defined
- sap_hana_preconfigure_thp is undefined or sap_hana_preconfigure_thp | length == 0
- ansible_distribution == 'RedHat'
- (ansible_distribution_major_version == '9' and
__sap_hana_preconfigure_fact_ansible_distribution_minor_version | int >= 2) or
ansible_distribution_major_version == '10'

- name: Set fact for THP if 'sap_hana_preconfigure_thp' is defined
ansible.builtin.set_fact:
__sap_hana_preconfigure_fact_thp: "{{ sap_hana_preconfigure_thp }}"
when:
- sap_hana_preconfigure_thp is defined and sap_hana_preconfigure_thp

- name: Set THP to '{{ __sap_hana_preconfigure_fact_thp }}' at boot time
ansible.builtin.command: /bin/true
notify: __sap_hana_preconfigure_grubby_thp_handler
changed_when: true
when: not ( __sap_hana_preconfigure_register_proc_cmdline_thp['content'] | b64decode | regex_findall('transparent_hugepage=' + __sap_hana_preconfigure_fact_thp) )
tags: grubconfig

- name: Configure - Get initial status of THP
ansible.builtin.command: cat /sys/kernel/mm/transparent_hugepage/enabled
register: __sap_hana_preconfigure_register_thp_status_before
changed_when: false

- name: Set THP to '{{ __sap_hana_preconfigure_fact_thp }}' on the running system
ansible.builtin.shell: echo '{{ __sap_hana_preconfigure_fact_thp }}' > /sys/kernel/mm/transparent_hugepage/enabled
changed_when: true
- name: Add boot command line args for configuring THP if applicable
when:
- not ansible_check_mode
- __sap_hana_preconfigure_register_thp_status_before.stdout.split('[')[1].split(']')[0] != __sap_hana_preconfigure_fact_thp

- name: Configure - Get the status of THP
ansible.builtin.command: cat /sys/kernel/mm/transparent_hugepage/enabled
register: __sap_hana_preconfigure_register_thp_status
ignore_errors: true
changed_when: false

- name: Display the status of THP
ansible.builtin.debug:
var: __sap_hana_preconfigure_register_thp_status.stdout_lines, __sap_hana_preconfigure_register_thp_status.stderr_lines
- (sap_hana_preconfigure_thp is defined and sap_hana_preconfigure_thp | length > 0)
or __sap_hana_preconfigure_boot_command_line_args['thp']['arch'] is defined
block:

- name: Add boot command line args for configuring THP
ansible.builtin.set_fact:
__sap_hana_preconfigure_boot_command_line_args_final: >-
{{ __sap_hana_preconfigure_boot_command_line_args_final
+ ['transparent_hugepage=' + __sap_hana_preconfigure_fact_thp] }}

- name: Configure - Get initial status of THP
ansible.builtin.command: cat /sys/kernel/mm/transparent_hugepage/enabled
register: __sap_hana_preconfigure_register_thp_status_before
changed_when: false

- name: Set THP to '{{ __sap_hana_preconfigure_fact_thp }}' on the running system
ansible.builtin.shell: echo '{{ __sap_hana_preconfigure_fact_thp }}' > /sys/kernel/mm/transparent_hugepage/enabled
changed_when: true
when:
- not ansible_check_mode
- __sap_hana_preconfigure_register_thp_status_before.stdout.split('[')[1].split(']')[0] != __sap_hana_preconfigure_fact_thp

- name: Configure - Get the status of THP
ansible.builtin.command: cat /sys/kernel/mm/transparent_hugepage/enabled
register: __sap_hana_preconfigure_register_thp_status
ignore_errors: true
changed_when: false

- name: Display the status of THP
ansible.builtin.debug:
var: __sap_hana_preconfigure_register_thp_status.stdout_lines, __sap_hana_preconfigure_register_thp_status.stderr_lines
25 changes: 9 additions & 16 deletions roles/sap_hana_preconfigure/tasks/RedHat/generic/enable-tsx.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
# SPDX-License-Identifier: Apache-2.0
---

- name: Get boot command line
ansible.builtin.slurp:
src: /proc/cmdline
register: __sap_hana_preconfigure_register_proc_cmdline

- name: Enable TSX at boot time
ansible.builtin.command: /bin/true
notify: __sap_hana_preconfigure_grubby_update_handler
changed_when: true
- name: Add boot command line args for configuring TSX
ansible.builtin.set_fact:
__sap_hana_preconfigure_boot_command_line_args_final: >-
{{ __sap_hana_preconfigure_boot_command_line_args_final + [__sap_hana_preconfigure_kernel_arg_line_item] }}
loop: "{{ __sap_hana_preconfigure_boot_command_line_args['tsx']['args'] }}"
loop_control:
loop_var: __sap_hana_preconfigure_kernel_arg_line_item
when:
- ansible_architecture == 'x86_64'
- ansible_distribution == 'RedHat'
- (ansible_distribution_major_version >= '9') or
(ansible_distribution_major_version == '8' and
__sap_hana_preconfigure_fact_ansible_distribution_minor_version | int >= 3)
- not ( __sap_hana_preconfigure_register_proc_cmdline['content'] | b64decode | regex_findall('tsx=on') )
tags: grubconfig
- __sap_hana_preconfigure_boot_command_line_args['tsx']['arch'] is defined
- ansible_architecture in __sap_hana_preconfigure_boot_command_line_args['tsx']['arch']
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# SPDX-License-Identifier: Apache-2.0
---

- name: Get all kernel command line args for all grub entries
ansible.builtin.shell: set -o pipefail && grubby --info=ALL
register: __sap_hana_preconfigure_register_grubby_info_all
check_mode: false
changed_when: false

- name: Validate the grubby output
ansible.builtin.fail:
msg: "FAIL: No grub or grub args entries found!"
when:
- __sap_hana_preconfigure_register_grubby_info_all.stdout == ""
- "'args=' not in __sap_hana_preconfigure_register_grubby_info_all.stdout"

- name: Store all lines containing the kernel arguments
ansible.builtin.set_fact:
__sap_hana_preconfigure_fact_all_kernel_args_lines: >-
{{
__sap_hana_preconfigure_register_grubby_info_all.stdout |
regex_findall('args="([^"]*)"')
}}

# We first identify kernel args which are missing in at least one grub entry
- name: Identify missing kernel args
ansible.builtin.set_fact:
__sap_hana_preconfigure_fact_missing_kernel_args: >-
{{
__sap_hana_preconfigure_fact_missing_kernel_args + [__sap_hana_preconfigure_missing_kernel_arg_item]
}}
loop: "{{ __sap_hana_preconfigure_boot_command_line_args_final }}"
loop_control:
loop_var: __sap_hana_preconfigure_missing_kernel_arg_item
when: >-
__sap_hana_preconfigure_fact_all_kernel_args_lines |
select('search', __sap_hana_preconfigure_missing_kernel_arg_item.split('=')[0] + '=') |
list | length < __sap_hana_preconfigure_fact_all_kernel_args_lines | length

# We then identify kernel args which are
# - either not set correctly in all grub entries, or
# - set differently (meaning that the arg/value combination for a desired arg occurs more than once)
- name: Identify kernel args to be updated
ansible.builtin.set_fact:
__sap_hana_preconfigure_kernel_args_to_be_updated: >-
{{
__sap_hana_preconfigure_kernel_args_to_be_updated + [__sap_hana_preconfigure_kernel_arg_to_be_updated_item]
}}
loop: "{{ __sap_hana_preconfigure_boot_command_line_args_final }}"
loop_control:
loop_var: __sap_hana_preconfigure_kernel_arg_to_be_updated_item
when: >-
(
__sap_hana_preconfigure_kernel_arg_to_be_updated_item not in
__sap_hana_preconfigure_fact_all_kernel_args_lines
| join(' ') | split | unique
) or (
__sap_hana_preconfigure_fact_all_kernel_args_lines
| join(' ') | split | unique
| select('search', __sap_hana_preconfigure_kernel_arg_to_be_updated_item.split('=')[0]) | list | length > 1
)

- name: Display grub and kernel args information
ansible.builtin.debug:
msg: |
Number of grub entries: {{ __sap_hana_preconfigure_fact_all_kernel_args_lines | length }}
Required arguments: {{ __sap_hana_preconfigure_boot_command_line_args_final }}
Missing kernel args: {{ __sap_hana_preconfigure_fact_missing_kernel_args }}
Kernel args to be updated: {{ __sap_hana_preconfigure_kernel_args_to_be_updated }}

- name: Set fact for all required kernel arg updates
ansible.builtin.set_fact:
__sap_hana_preconfigure_fact_kernel_args_to_be_set: >-
{{ (__sap_hana_preconfigure_fact_missing_kernel_args
+ __sap_hana_preconfigure_kernel_args_to_be_updated) | unique
}}

- name: Display kernel args to be set
ansible.builtin.debug:
msg: "Kernel args to be set: '{{ __sap_hana_preconfigure_fact_kernel_args_to_be_set }}'"

- name: Construct the grubby command for configuring the kernel command line entries
ansible.builtin.set_fact:
__sap_hana_preconfigure_fact_grubby_command: >-
grubby --args="{{ __sap_hana_preconfigure_fact_kernel_args_to_be_set | join(' ') | trim }}" --update-kernel=ALL
when:
- __sap_hana_preconfigure_fact_kernel_args_to_be_set | length > 0

- name: Display the grubby command to be run
ansible.builtin.debug:
msg: "Grubby command: '{{ __sap_hana_preconfigure_fact_grubby_command }}'"
when:
- __sap_hana_preconfigure_fact_kernel_args_to_be_set | length > 0

# Reason for noqa: The command does not change anything but if we set 'changed_when: true',
# the handler will not be notified.
- name: Trigger kernel command line update if necessary # noqa no-changed-when
ansible.builtin.command:
cmd: /bin/true
notify: __sap_hana_preconfigure_grubby_update_handler
when:
- __sap_hana_preconfigure_fact_kernel_args_to_be_set | length > 0
Loading