From a8eaaafac666c88c553af9248db51d2a14e659ed Mon Sep 17 00:00:00 2001 From: yangpan Date: Thu, 14 Dec 2023 11:14:46 +0800 Subject: [PATCH] modify bolt_optimize_bin --- src/sysboostd/aot.rs | 22 ++++++++++++++++++++++ src/sysboostd/bolt.rs | 33 ++++++++++++++------------------- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/sysboostd/aot.rs b/src/sysboostd/aot.rs index 712f3a7..b31b745 100644 --- a/src/sysboostd/aot.rs +++ b/src/sysboostd/aot.rs @@ -111,6 +111,28 @@ pub fn set_app_link_flag(path: &String, is_set: bool) -> i32 { return ret; } +pub fn set_rto_link_flag(path: &String, is_set: bool) -> i32 { + let mut args: Vec = Vec::new(); + if is_set { + args.push("--set-rto".to_string()); + } else { + args.push("--unset-rto".to_string()); + } + + // 回滚场景, 路径是软链接要转换为真实路径 + let real_path = match fs::canonicalize(path) { + Ok(p) => p, + Err(e) => { + log::error!("get realpath failed: {}", e); + return -1; + } + }; + + args.push(format!("{}", real_path.to_string_lossy())); + let ret = run_child(SYSBOOST_PATH, &args); + return ret; +} + // 生成rto文件 // rto文件先生成到临时文件, 然后mv到最终路径, 避免并发操作文件问题 // sysboost --output=/usr/bin/bash.tmp.rto -static /usr/bin/bash lib1 lib2 diff --git a/src/sysboostd/bolt.rs b/src/sysboostd/bolt.rs index 0fd86f9..784a695 100644 --- a/src/sysboostd/bolt.rs +++ b/src/sysboostd/bolt.rs @@ -9,11 +9,11 @@ // See the Mulan PSL v2 for more details. // Create: 2023-8-28 -use crate::common::set_thp; use crate::common::is_arch_x86_64; use crate::config::RtoConfig; use crate::lib::process_ext::run_child; use crate::config::get_config; +use crate::aot::set_rto_link_flag; use std::fs; use std::path::Path; @@ -59,25 +59,20 @@ fn bolt_optimize_bin(conf: &RtoConfig) -> i32 { return -1; } }; - let elf_bak_path = elf_path.with_extension("bak"); - match fs::copy(&elf_path, &elf_bak_path) { - Ok(_) => {} - Err(e) => { - log::error!("Copy failed: {}", e); - return -1; - } - } - args.push(elf_bak_path.to_str().unwrap().to_string()); - args.push("-o".to_string()); + let rto_path = elf_path.with_extension("rto"); args.push(elf.split_whitespace().collect()); - + args.push("-o".to_string()); + args.push(rto_path.to_str().unwrap().to_string()); + let real_profile_path = get_profile_path(conf); if real_profile_path != "" { args.push(format!("-data={}", real_profile_path)); } - - let ret = run_child("/usr/bin/llvm-bolt", &args); - + let mut ret = run_child("/usr/bin/llvm-bolt", &args); + if ret != 0 { + return ret; + } + ret = set_rto_link_flag(&rto_path.to_str().unwrap().to_string(), true); return ret; } @@ -140,10 +135,10 @@ pub fn bolt_optimize(conf: &RtoConfig) -> i32 { return ret; } else { let ret = bolt_optimize_bin(&conf); - // 如果优化程序是mysqld, 则开启透明大页 - if is_mysqld(conf) { - set_thp(); - } + // rto加载流程会使用大页功能,不需要开启系统透明大页 + // if is_mysqld(conf) { + // //set_thp(); + // } return ret; } } -- Gitee