diff --git a/gdb/testsuite/gdb.mi/mi-cmd-param-changed.exp b/gdb/testsuite/gdb.mi/mi-cmd-param-changed.exp
index 8ffafe296f6..bbe9cf36236 100644
--- a/gdb/testsuite/gdb.mi/mi-cmd-param-changed.exp
+++ b/gdb/testsuite/gdb.mi/mi-cmd-param-changed.exp
@@ -13,6 +13,9 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+# Do this here before we start GDB for the test.
+set scheduler_locking_supported [target_supports_scheduler_locking]
+
 load_lib mi-support.exp
 set MIFLAGS "-i=mi"
 
@@ -24,37 +27,40 @@ if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {deb
 }
 
 proc test_command_param_changed { } {
+    global scheduler_locking_supported
+
     with_test_prefix "cmd param" {
 	if [mi_gdb_start] {
 	    return
 	}
 	mi_run_to_main
 
-	foreach opt { "on" "off" "step" } {
-	    mi_gdb_test "set scheduler-locking ${opt}" \
-		".*=cmd-param-changed,param=\"scheduler-locking\",value=\"${opt}\".*\\^done" \
-		"\"set scheduler-locking ${opt}\""
-	}
-	foreach opt { "on" "off" "step" } {
-	    mi_gdb_test "interpreter-exec console \"set scheduler-locking ${opt}\"" \
-		".*=cmd-param-changed,param=\"scheduler-locking\",value=\"${opt}\".*\\^done" \
-		"interpreter-exec \"set scheduler-locking ${opt}\""
+	if { $scheduler_locking_supported } {
+	    foreach opt { "on" "off" "step" } {
+		mi_gdb_test "set scheduler-locking ${opt}" \
+		    ".*=cmd-param-changed,param=\"scheduler-locking\",value=\"${opt}\".*\\^done" \
+		    "\"set scheduler-locking ${opt}\""
+	    }
+	    foreach opt { "on" "off" "step" } {
+		mi_gdb_test "interpreter-exec console \"set scheduler-locking ${opt}\"" \
+		    ".*=cmd-param-changed,param=\"scheduler-locking\",value=\"${opt}\".*\\^done" \
+		    "interpreter-exec \"set scheduler-locking ${opt}\""
+	    }
+	    # Don't emit MI notification for request from MI.
+	    mi_gdb_test "-gdb-set scheduler-locking on" \
+		{\^done} \
+		"\"set scheduler-locking on\" no event (requested by MI)"
+	    mi_gdb_test "interpreter-exec mi \"-gdb-set scheduler-locking step\"" \
+	    "\\&\"interpreter-exec mi .*\"-gdb-set scheduler-locking step.*\"\\\\n\"\r\n\\^done\r\n\\^done" \
+		"\"set scheduler-locking step\" no event (requested by MI interp)"
+	    mi_gdb_test "set scheduler-locking step" \
+		"\\&\"set scheduler-locking step\\\\n\"\r\n\\^done" \
+		"\"set scheduler-locking stepr\" no event"
 	}
-	# Don't emit MI notification for request from MI.
-	mi_gdb_test "-gdb-set scheduler-locking on" \
-	    {\^done} \
-	    "\"set scheduler-locking on\" no event (requested by MI)"
+
 	mi_gdb_test "-exec-arguments foo" {\^done} \
 	    "\"-exec-arguments foo\" no event"
 
-	mi_gdb_test "interpreter-exec mi \"-gdb-set scheduler-locking step\"" \
-	    "\\&\"interpreter-exec mi .*\"-gdb-set scheduler-locking step.*\"\\\\n\"\r\n\\^done\r\n\\^done" \
-	    "\"set scheduler-locking step\" no event (requested by MI interp)"
-	mi_gdb_test "set scheduler-locking step" \
-	    "\\&\"set scheduler-locking step\\\\n\"\r\n\\^done" \
-	    "\"set scheduler-locking stepr\" no event"
-
-
 	foreach command { "remotecache" "check type" } {
 
 	    # The default value of each command option may be different, so we first
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 3e2f755e5b7..dd2c57cbc2d 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -6053,6 +6053,76 @@ gdb_caching_proc gdb_target_symbol_prefix {
     return $prefix
 }
 
+# Return 1 if target supports scheduler locking, otherwise return 0.
+
+gdb_caching_proc target_supports_scheduler_locking {
+    global gdb_prompt
+
+    set me "gdb_target_supports_scheduler_locking"
+
+    set src [standard_temp_file has_schedlock[pid].c]
+    set exe [standard_temp_file has_schedlock[pid].x]
+
+    gdb_produce_source $src {
+	int main () {
+	    return 0;
+	}
+    }
+
+    verbose "$me:  compiling testfile $src" 2
+    set compile_flags {debug nowarnings}
+    set lines [gdb_compile $src $exe executable $compile_flags]
+    file delete $src
+
+    if ![string match "" $lines] then {
+        verbose "$me:  testfile compilation failed, returning 0" 2
+        return 0
+    }
+
+    clean_restart $exe
+    gdb_start_cmd
+
+    set supports_schedule_locking -1
+    set current_schedule_locking_mode ""
+
+    set test "reading current scheduler-locking mode"
+    gdb_test_multiple "show scheduler-locking" $test {
+	-re "Mode for locking scheduler during execution is \"(\[\^\"\]*)\".*$gdb_prompt" {
+	    set current_schedule_locking_mode $expect_out(1,string)
+	}
+	-re "$gdb_prompt $" {
+	    set supports_schedule_locking 0
+	}
+	timeout {
+	    set supports_schedule_locking 0
+	}
+    }
+
+    if { $supports_schedule_locking == -1 } {
+	set test "checking for scheduler-locking support"
+	gdb_test_multiple "set scheduler-locking $current_schedule_locking_mode" $test {
+	    -re "Target '\[^'\]+' cannot support this command\..*$gdb_prompt $" {
+		set supports_schedule_locking 0
+	    }
+	    -re "$gdb_prompt $" {
+		set supports_schedule_locking 1
+	    }
+	    timeout {
+		set supports_schedule_locking 0
+	    }
+	}
+    }
+
+    if { $supports_schedule_locking == -1 } {
+	set supports_schedule_locking 0
+    }
+
+    gdb_exit
+    remote_file build delete $exe
+    verbose "$me:  returning $supports_schedule_locking" 2
+    return $supports_schedule_locking
+}
+
 # gdb_target_symbol returns the provided symbol with the correct prefix
 # prepended.  (See gdb_target_symbol_prefix, above.)
 
